*IAT SCORING ALGORITHM FROM GREENWALD, NOSEK, & BANAJI, 2003
LAST UPDATE: 03/03/04

This macro will transform a datafile with raw trial latencies (stored as one line per response) 
for a standard format IAT (7 blocks) into a one line summary per subject of the IAT effect using
GNB's new scoring algorithm.

To use this algorithm for your SAS program, perform these two steps:  
(1) Run this script.  The macro should then be loaded into SAS's active memory.  
(2) In your SAS program, enter the following statement 

%iatCalc(libIn, libOut, indata, outdata, BLOCNAME, SESHID, TRLLATNC, TRLERROR, VERROR, VEXTREME, VSD)

and replace the dummy values with the ones that correspond to your own datafiles and variable names.  


Descriptions of what the macro expects for input, and what it will output are below.  Also, at the 
bottom of this commenting section, there is a sample SAS script that would invoke this macro (assuming 
that you have already run the macro to get it into SAS's active memory).

   The macro expects the following types of libraries, datafiles, and data:
      libIn     = input SAS library name
      libOut    = output SAS library name
      indata    = filename of input SAS dataset in the input SAS library
      outdata   = filename for the output SAS dataset in the output SAS library
      BLOCNAME  = variable name for block identifier in the indata file: alphanumeric indication of the 
                  four trial blocks ('B3', 'B4', 'B6', 'B7' are critical blocks corresponding 
                  to B3, B4, B6, and B7 from GNB, 2002).  At present the macro requires that the variable 
                  passed here uses the names 'B3', 'B4', 'B6', 'B7' to refer to the B3-B7 blocks
	  SESHID    = variable name for unique subject identifier in the indata file
	  TRLLATNC  = variable name for latency of response for trial in the indata file
	  TRLERROR  = variable name for error coding: 0 if initial response was correct, 1 if initial response 
                  was incorrect in the indata file
      VERROR    = value: if '1' the algorithm will use error trial latencies, if '2' the algorithm will replace 
                  error trial latencies with blockmean+600
      VEXTREME  = value: if '1' the algorithm provides no treatment of extreme values, if '2' the algorithm
                  will delete trials <400ms
      VSTD      = value: if '1' the block standard deviation is performed including corrected error trials,
                  if '2' the block standard deviation is performed on correct responses only (1 is standard)

   The macro will output the following variables to the outdata file:
      SESHID  = unique subject identifier
      SUBEXCL = 0 for inclusion data, 1 for excluded data, 2 for incomplete data
      MB3     = mean of trial latencies for B3
      MB4     = mean of trial latencies for B4
      MB6     = mean of trial latencies for B6
      MB7     = mean of trial latencies for B7
      CS1     = standard deviation for B3 and B6 trials combined (correct trials only)
      CS2     = standard deviation for B4 and B7 trials combined (correct trials only)
      AS1     = standard deviation for B3 and B6 trials combined (all trials)
      AS2     = standard deviation for B4 and B7 trials combined (all trials)
      EB3     = percent errors of trials for B3
      EB4     = percent errors of trials for B4
      EB6     = percent errors of trials for B6
      EB7     = percent errors of trials for B7
      FB3     = percent fast responses of trials for B3
      FB4     = percent fast responses of trials for B4
      FB6     = percent fast responses of trials for B6
      FB7     = percent fast responses of trials for B7
      DIFF1   = MB6 - MB3
      DIFF2   = MB7 - MB4
      IAT1    = DIFF1/STD1
      IAT2    = DIFF2/STD2
	  IAT     = mean of IAT1 and IAT2
;

/* SAMPLE SAS SCRIPT THAT USES THIS MACRO ASSUMING THAT IT IS IN ACTIVE SAS MEMORY
This sample script opens two libraries called 'web' and 'outdata'. In the 'web' library a SAS file 
named 'iatrace350000' already exists and will be pulled into active memory by the macro.  When the macro 
finishes it will output the result data into a file in the library 'outdata' called 'Ciatrace350000'. The 
information coding the name of the block is in the variable BLOCK (which is passed to 'BLOCNAME' for
the algorithm). The information coding subject ID is SUB (passed to 'SESHID').  The information coding
the latency of each trial is in LATENCY (passed to TRLLATNC).  The information coding whether an error
was made on each trial is in ERROR (passed to TRLERROR).  And, the setting '2' for VERROR means that 
error latencies will be replaced with the blockmean+600.  The setting '2' for VEXTREME means that responses
faster than 400ms will be deleted before calculating the IAT effect. The setting '1' for VSTD means that 
the standard deviations will be calculated after recombining error trials so the range of D values is bounded 
between (-2,2).  When the algorithm finishes and saves the output, the proc means statement will calculate a 
mean of the IAT effects across subjects (after excluding 'bad' subjects).

libname web 'H:\raceatt\';
libname outdata 'H:\raceattclean\';
%iatCalc(web, outdata, iatrace350000, Ciatrace350000, BLOCK, SUB, LATENCY, ERROR, 2, 2,1);
proc means (data=outdata.Ciatrace350000);var IAT;where SUBEXCL=0;run;
*/

/*MACROS for NEW IMPLICIT ASSOCIATION TEST SCORING ALGORITHM (Greenwald, Nosek, & Banaji, 2002)*/
%macro iatCalc(libIn, libOut, indata, outdata, BLOCNAME, SESHID, TRLLATNC, TRLERROR, VERROR, VEXTREME, VSTD);
%let divide= /; %let multiply= *; %let add = +; %let subtract = -;
%iatAlgorithm(libIn=&libIn, libOut=&libOut, indata=&indata, outdata=&outdata, BLOCNAME=&BLOCNAME, 
              SESHID=&SESHID, TRLLATNC=&TRLLATNC, TRLERROR=&TRLERROR, VERROR=&VERROR, VEXTREME=&VEXTREME, VSTD=&VSTD);run;
%mend iatCalc;

%macro iatAlgorithm(libIn, libOut, indata, outdata, BLOCNAME, SESHID, TRLLATNC, TRLERROR, VERROR, VEXTREME, VSTD);
data IAT; set &libIn..&indata; 
%*PRELIMINARY STEPS FOR HANDLING WEBDATA FORMATS;
    keep &BLOCNAME &SESHID &TRLLATNC &TRLERROR;
proc sort data=iat; by &SESHID &BLOCNAME;	
	%*options nonotes; %*suppress all Notes to log;	

data IAT; set IAT;

%*STEP 1: Include data from B3, B4, B6, B7;
   if &BLOCNAME in ('B3', 'B4', 'B6', 'B7') then ;
   else delete;

%*STEP 2a: Eliminate trial latencies > 10,000ms;
   if &TRLLATNC > 10000 then delete;

%*STEP 2b: Eliminate subjects for whom more than 10% of trials have latencies < 300ms;
   else if &TRLLATNC < 0 then delete; %*for miscoded data in datafile indicating negative response times;
   else if -1 < &TRLLATNC < 300 then FAST = 1;
   else FAST = 0;

data FASTDATA; set IAT; keep &SESHID &BLOCNAME FAST;
proc sort; by &SESHID &BLOCNAME;
proc means data=IAT noprint; by &SESHID &BLOCNAME; var FAST; output out=means mean=MEAN;
proc transpose data=means prefix=F name=name out=FASTMEAN; by &SESHID; id &BLOCNAME;
data FASTMEAN; set FASTMEAN; where name='MEAN'; FASTM = mean(FB3, FB4, FB6, FB7);
   if FASTM > .10 then SUBEXCL = 1; else SUBEXCL = 0; 
   %*SUBEXCL = 0 (include data), 1 (exclude data - too many fast responses), 2 (exclude data - missing data);
   %*The SUBEXCL variable needed to be reintroduced to the final dataset in STEP 12;

%*STEP 3: Use all trials;
   %*in the conventional algorithm the first two trials of each block would be dropped here;

%*STEP 4: No extreme value treatment <or> delete trial with latencies <400ms;
data IAT; set IAT; 
    %*if &VEXTREME = 1 then do nothing here;
    if &VEXTREME = 2 then do; if &TRLLATNC < 400 then delete; end;

proc sort data=IAT; by &SESHID &BLOCNAME;

%*STEP 5: Compute mean of correct latencies for each block;
data CORR; set IAT;
   %*if &VERROR is 1 then means and SDs will be calculated for the entire set of latencies;
   if &VERROR = 2 then do; if &TRLERROR NE 0 then delete; end;
   keep &SESHID &BLOCNAME &TRLLATNC &TRLERROR;
proc means data=CORR noprint; by &SESHID &BLOCNAME; var &TRLLATNC; output out=means mean=MEAN;
proc transpose data=means prefix=M name=name out=CORRMEAN; by &SESHID; id &BLOCNAME;
data CORRMEAN; set CORRMEAN; where name='MEAN';

%*STEP 6a: Compute pooled SD for B3 & B6, and separately for B4 & B7 for correct trials only;
data SD; set CORR;
   if &TRLERROR NE 0 then delete;  *drop error trials;
   if &BLOCNAME in ('B3', 'B6') then TD = '1';
   else if &BLOCNAME in ('B4', 'B7') then TD = '2';
   else delete;
   drop &BLOCNAME;
proc sort data=SD; by &SESHID TD;
proc means data=SD noprint; by &SESHID TD; var &TRLLATNC; output out=means std=STD;
proc transpose data=means prefix=CS name=name out=CORRSTD2; by &SESHID; id TD;
data CORRSTD2; set CORRSTD2; where name='STD';

%*STEP 6b: Compute pooled SD for B3 & B6, and separately for B4 & B7 including error trials;
data SD; merge IAT CORRMEAN; by &SESHID;
   if &TRLERROR < 0 then delete;
   else if &TRLERROR > 1 then delete; %*get rid of coding errors;
   else if &TRLERROR = 1 and &VERROR = 2 then do;
      if &BLOCNAME in ('B3') then &TRLLATNC = MB3 + 600;
	  else if &BLOCNAME in ('B4') then &TRLLATNC = MB4 + 600;
	  else if &BLOCNAME in ('B6') then &TRLLATNC = MB6 + 600;
	  else if &BLOCNAME in ('B7') then &TRLLATNC = MB7 + 600;
   end;
   if &BLOCNAME in ('B3', 'B6') then TD = '1';
   else if &BLOCNAME in ('B4', 'B7') then TD = '2';
   else delete;
   drop &BLOCNAME;
proc sort data=SD; by &SESHID TD;
proc means data=SD noprint; by &SESHID TD; var &TRLLATNC; output out=means std=STD;
proc transpose data=means prefix=AS name=name out=CORRSTD1; by &SESHID; id TD;
data CORRSTD1; set CORRSTD1; where name='STD';

%*STEP 7: Replace error latencies with block mean + 600ms 
<or> use latency from stimulus onset to correct response (when correct response is required);
data ERR; set IAT;
   keep &SESHID &BLOCNAME &TRLERROR;
   if &TRLERROR < 0 then delete;
   else if &TRLERROR > 1 then delete; %*get rid of coding errors;
proc means data=ERR noprint; by &SESHID &BLOCNAME; var &TRLERROR; output out=means mean=MEAN;
proc transpose data=means prefix=E name=name out=ERRMEAN; by &SESHID; id &BLOCNAME;
data ERRMEAN; set ERRMEAN; where name='MEAN';

%*STEP 7 continued: combining data;
data COMBINE; merge CORRMEAN CORRSTD1 CORRSTD2 ERRMEAN FASTMEAN; by &SESHID; %*combining datasets for calculating final means;
   if &VERROR=2 then do;
      array BLOCKMeans(*) MB: ;
      array BLOCKCstds(*) CS: ;
	  array BLOCKAstds(*) AS: ;
      array BLOCKErrs(*) EB: ;
      do i=1 to dim(BLOCKMeans); %*for each of the four blocks replace error trials with mean + 600ms;
	     BLOCKMeans{i} = (1-BLOCKErrs{i})*BLOCKMeans{i} + (BLOCKErrs{i})*(BLOCKMeans{i}+600);			
      end;
   end;

%*STEP 8: No transformation of latencies;
    %*in the conventional algorithm, raw latencies would be log transformed prior to the transposing in the current format;

%*STEP 9: Average latencies for each of the four blocks;
    %*this step was already accomplished in the do loop above;

%*STEP 10: Compute two differences B6-B3 and B7-B4 (does not account for pairing order);
   DIFF1 = MB6 - MB3;
   DIFF2 = MB7 - MB4;

%*STEP 11: Divide each difference by associated pooled SD from STEP 6a or 6b;
   If &VSTD = 2 then do;
      IAT1 = DIFF1/CS1;
      IAT2 = DIFF2/CS2;
   end;
   else do; %*IF VSTD = 1 also set as default;
      IAT1 = DIFF1/AS1;
	  IAT2 = DIFF2/AS2;
   end; 

%*STEP 12: Average quotients from STEP 11;
   IAT = mean(IAT1, IAT2);

%*if there is missing data, do mark data as excluded (SUBEXCL=2);
   do i=1 to dim(BLOCKMeans);
      if BLOCKMeans{i} = . then SUBEXCL = 2;
   end;
data &libout..&outdata (drop=i name);
	set COMBINE;
run;
%mend iatAlgorithm;
*END OF ALGORITHM;

LIBNAME web_in 'C:\SAS data\Mall_In'; 
LIBNAME web_out 'C:\SAS data\Mall_Out';
LIBNAME race 'C:\SAS data\Mall_Out\race';

DATA web_in.researchexplicit; 
   	INFORMAT Questionnaire_Name $20.;
	INFORMAT Question_Name $18.;
	INFORMAT Study_Name $50.; 
   	INFILE 'C:\SAS data\Mall_In\researchexplicit.txt'  
                 DELIMITER='09'x FIRSTOBS=2; 
   	INPUT Task_Number Question_Number Questionnaire_Name $ Question_Name $ Question_Response $ Attempt Study_Name $ Session_ID;  
 /*  DROP Study_Name; */ 
PROC CONTENTS;
RUN; 
 
DATA web_in.labexplicit; 
   	INFORMAT Questionnaire_Name $20.;
	INFORMAT Question_Name $18.;
	INFORMAT Study_Name $50.; 
   	INFILE 'C:\SAS data\Mall_In\labexplicit.txt'  
                 DELIMITER='09'x FIRSTOBS=2; 
   	INPUT Task_Number Question_Number Questionnaire_Name $ Question_Name $ Question_Response $ Attempt Study_Name $ Session_ID;  
 /*  DROP Study_Name; */ 
PROC CONTENTS;
RUN; 

DATA web_in.homeexplicit; 
   	INFORMAT Questionnaire_Name $20.;
	INFORMAT Question_Name $18.;
	INFORMAT Study_Name $50.; 
   	INFILE 'C:\SAS data\Mall_In\homeexplicit.txt'  
                 DELIMITER='09'x FIRSTOBS=2; 
   	INPUT Task_Number Question_Number Questionnaire_Name $ Question_Name $ Question_Response $ Attempt Study_Name $ Session_ID;  
 /*  DROP Study_Name; */ 
PROC CONTENTS;
RUN; 

 DATA web_in.researchdemo; 
  	INFORMAT Characteristic $20.;
	INFORMAT Study_Name $50.;
	INFORMAT value $25.; 
  	INFILE 'C:\SAS data\Mall_In\researchdemographics.txt' DELIMITER='09'x FIRSTOBS=2; 
  	INPUT Characteristic $ Value $ User_ID Study_Name $; 
 /*  DROP Study_Name;  */
PROC CONTENTS;
RUN; 
 
DATA web_in.researchsessions; 
	INFORMAT Study_Name $50.;
	INFORMAT Session_Date $8.;
	INFORMAT Creation_Date $30.;
	INFORMAT Last_Update_Date $30.;  
   	INFILE 'C:\SAS data\Mall_In\researchsessions.txt'  
         DELIMITER='09'x  FIRSTOBS=2; 
   	INPUT Session_ID User_ID Study_Name $ Session_Date $ Session_Status $ Creation_Date Last_Update_Date; 
PROC CONTENTS;
RUN; 
  
DATA web_in.labsessions; 
	INFORMAT Study_Name $50.;
	INFORMAT Session_Date $8.;
	INFORMAT Creation_Date $30.;
	INFORMAT Last_Update_Date $30.;  
   	INFILE 'C:\SAS data\Mall_In\labsessions.txt'  
         DELIMITER='09'x  FIRSTOBS=2; 
   	INPUT Session_ID User_ID Study_Name $ Session_Date $ Session_Status $ Creation_Date Last_Update_Date; 
PROC CONTENTS;
RUN; 

DATA web_in.homesessions; 
	INFORMAT Study_Name $50.;
	INFORMAT Session_Date $8.;
	INFORMAT Creation_Date $30.;
	INFORMAT Last_Update_Date $30.;  
   	INFILE 'C:\SAS data\Mall_In\homesessions.txt'  
         DELIMITER='09'x  FIRSTOBS=2; 
   	INPUT Session_ID User_ID Study_Name $ Session_Date $ Session_Status $ Creation_Date Last_Update_Date; 
PROC CONTENTS;
RUN; 
  
DATA web_in.researchimplicit; 
   	INFORMAT Block_Pairing_Definition $40.;
	INFORMAT Study_Name $25.;
	INFORMAT Task_Name $37.;
	INFORMAT Trial_Name $15.;
	INFORMAT Trial_Response $15.;  
   	INFILE 'C:\SAS data\Mall_In\researchiat.txt'  
         DELIMITER='09'x FIRSTOBS=2; 
   	INPUT block_number block_name $ block_trial_count block_pairing_definition $ study_name $ task_number task_name $ 
          trial_number trial_name $ trial_response $ trial_latency trial_error session_id;
	DROP study_name; /*DROP Study_Name*/  
PROC CONTENTS;
RUN; 

DATA web_in.labimplicit; 
   	INFORMAT Block_Pairing_Definition $40.;
	INFORMAT Study_Name $25.;
	INFORMAT Task_Name $37.;
	INFORMAT Trial_Name $15.;
	INFORMAT Trial_Response $15.;  
   	INFILE 'C:\SAS data\Mall_In\labiat.txt'  
         DELIMITER='09'x FIRSTOBS=2; 
   	INPUT block_number block_name $ block_trial_count block_pairing_definition $ study_name $ task_number task_name $ 
          trial_number trial_name $ trial_response $ trial_latency trial_error session_id;
	DROP study_name; /*DROP Study_Name*/  
PROC CONTENTS;
RUN; 

DATA web_in.homeimplicit; 
   	INFORMAT Block_Pairing_Definition $40.;
	INFORMAT Study_Name $25.;
	INFORMAT Task_Name $37.;
	INFORMAT Trial_Name $15.;
	INFORMAT Trial_Response $15.;  
   	INFILE 'C:\SAS data\Mall_In\homeiat.txt'  
         DELIMITER='09'x FIRSTOBS=2; 
   	INPUT block_number block_name $ block_trial_count block_pairing_definition $ study_name $ task_number task_name $ 
          trial_number trial_name $ trial_response $ trial_latency trial_error session_id;
	DROP study_name; /*DROP Study_Name*/  
PROC CONTENTS;
RUN; 

DATA web_in.researchsessiontasks; 
	INFORMAT Study_Name $50.;               
	INFORMAT Session_Last_Update_Date $21.; 
	INFORMAT Session_Creation_Date $21.; 
    INFORMAT Task_ID $20.;                  
	INFORMAT Task_Creation_Date $21.;         
	INFORMAT Session_Date $21.;  
    INFORMAT Task_URL $128.;                
	INFORMAT User_Agent $16.;                          
	INFORMAT Session_Created_By $24.; 
 	INFILE 'C:\SAS data\Mall_In\researchsessionTasks.txt' DELIMITER='09'x LRECL=2000 FIRSTOBS  =  2; 
  	INPUT  Session_ID Task_Number Task_ID $ Task_URL $ User_Agent $ Study_URL $ Task_Status $ Task_Sequence $ Task_Creation_Date 
           $ User_ID Study_Name $ Session_Date $ Session_Status $ Session_Creation_Date $ Session_Created_By $ Session_Last_Update_Date $; 
PROC CONTENTS;
RUN;        
  
DATA web_in.labsessiontasks; 
	INFORMAT Study_Name $50.;               
	INFORMAT Session_Last_Update_Date $21.; 
	INFORMAT Session_Creation_Date $21.; 
    INFORMAT Task_ID $20.;                  
	INFORMAT Task_Creation_Date $21.;         
	INFORMAT Session_Date $21.;  
    INFORMAT Task_URL $128.;                
	INFORMAT User_Agent $16.;                          
	INFORMAT Session_Created_By $24.; 
 	INFILE 'C:\SAS data\Mall_In\labsessionTasks.txt' DELIMITER='09'x LRECL=2000 FIRSTOBS  =  2; 
  	INPUT  Session_ID Task_Number Task_ID $ Task_URL $ User_Agent $ Study_URL $ Task_Status $ Task_Sequence $ Task_Creation_Date 
           $ User_ID Study_Name $ Session_Date $ Session_Status $ Session_Creation_Date $ Session_Created_By $ Session_Last_Update_Date $; 
PROC CONTENTS;
RUN;

DATA web_in.homesessiontasks; 
	INFORMAT Study_Name $50.;               
	INFORMAT Session_Last_Update_Date $21.; 
	INFORMAT Session_Creation_Date $21.; 
    INFORMAT Task_ID $20.;                  
	INFORMAT Task_Creation_Date $21.;         
	INFORMAT Session_Date $21.;  
    INFORMAT Task_URL $128.;                
	INFORMAT User_Agent $16.;                          
	INFORMAT Session_Created_By $24.; 
 	INFILE 'C:\SAS data\Mall_In\homesessionTasks.txt' DELIMITER='09'x LRECL=2000 FIRSTOBS  =  2; 
  	INPUT  Session_ID Task_Number Task_ID $ Task_URL $ User_Agent $ Study_URL $ Task_Status $ Task_Sequence $ Task_Creation_Date 
           $ User_ID Study_Name $ Session_Date $ Session_Status $ Session_Creation_Date $ Session_Created_By $ Session_Last_Update_Date $; 
PROC CONTENTS;
RUN;


*CLEANING RESEARCH STUDY;

/************************************************/
/*                                              */
/*        		Setting IAT Data Up 		    */
/*                                              */
/************************************************/

DATA temp; SET web_in.researchimplicit; 
IF BLOCK_NAME in ('BLOCK0', 'BLOCK1', 'BLOCK4') then delete;
IF TRIAL_ERROR = '0' THEN TRIALERROR = 0;
ELSE IF TRIAL_ERROR = '1' THEN TRIALERROR = 1;
KEEP trial_number block_name session_ID block_pairing_definition trial_latency trialerror task_name;
RUN;

PROC SORT DATA=temp;
BY session_id task_name block_name trial_number;
RUN;

DATA temp; SET temp;
repeat = 0;
IF session_ID = lag(session_id) and TASK_NAME= lag(TASK_NAME) AND BLOCK_NAME = lag(BLOCK_NAME) AND TRIAL_NUMBER = lag(TRIAL_NUMBER) 
THEN repeat=1; *if prior row is same as current row, mark as a repeat;

PROC SORT; 
BY session_ID; 
RUN;

PROC FREQ; 
TABLES repeat; 
RUN; 

DATA temp; SET temp;
IF repeat = 1 THEN DELETE; 
DROP repeat; 
RUN; *drop duplicate lines of data;



/************************************************/
/*                                              */
/*        SORTING THROUGH THE IAT              */
/*                                              */
/************************************************/
DATA reordered; SET temp;
IF task_name in ("demo_raceb") THEN DO;
IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B7';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B4';
END;
ELSE IF task_name in ("demo_racea") THEN DO;
	IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B4';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B7';
END;
RUN;



/*************************************************/
/* RACE IAT (Higher scores indicate pro-white) */
/*************************************************/
DATA web_in.race_iat; SET reordered;
WHERE task_name IN ("demo_racea", "demo_raceb");
DROP BLOCK_NAME;
run;

%iatCalc(web_in, race, race_iat, race_iat_clean, BLOCK, SESSION_ID, TRIAL_LATENCY, TRIALERROR, 1, 2, 1); 

DATA race.input; SET web_in.race_iat;   *pull up the raw dataset for use and keep only the necessary variables;
KEEP trial_number BLOCK block_pairing_definition session_id task_name trialerror trial_latency;

PROC SORT; 
BY session_ID BLOCK;  *sort by session and block so transpose function will work below;
RUN;

/*identifying block pairing definitions*/
DATA race.pairing; SET race.input; 
WHERE TRIAL_NUMBER = 1; 
KEEP session_ID BLOCK block_pairing_definition;

PROC TRANSPOSE DATA=race.pairing PREFIX=P NAME=name OUT=race.pairing; 
BY session_ID; 
VAR block_pairing_definition;
ID BLOCK;

PROC SORT DATA=race.PAIRING; 
BY SESSION_ID; 
RUN; *outputs a file with session_id and the block_pairing_defs for all blocks;

/*n per block - including extreme outliers;	vars=nBLOCK0, nBLOCK, ... ; set=ns*/
DATA race.ns; SET race.input; KEEP SESSION_ID BLOCK TRIAL_NUMBER;
PROC MEANS DATA=race.ns noprint; BY SESSION_ID BLOCK; VAR TRIAL_NUMBER; OUTPUT OUT=race.means n=N; 
PROC TRANSPOSE DATA=race.means PREFIX=N NAME=name OUT=race.spdmeans; BY SESSION_ID; ID BLOCK;
PROC SORT DATA=race.spdmeans; BY SESSION_ID;
DATA race.ns; SET race.spdmeans; WHERE name='N';
RUN; *outputs a file with the number of actual trials in each block;

/************************************************/
/*                                              */
/*        DIFFERENTATING THE CONDITIONS         */
/*                                              */
/************************************************/

DATA temp2; SET web_in.researchsessiontasks; 

PROC SORT; 
BY session_ID task_number task_url;

DATA temp2; SET temp2;
     DROP user_ID task_ID; 
     repeat=0;
	 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
	 task_url = tranwrd(task_url,"/user/brock/","");

     IF SESSION_ID = lag(SESSION_ID) and TASK_NUMBER = lag(TASK_NUMBER)
        and TASK_URL = lag(TASK_URL) THEN repeat=1;
/*
PROC MEANS; CLASS repeat; VAR session_id;RUN;*/

DATA temp2; SET temp2;
    IF repeat = 1 THEN delete;  *DROPping repeat DATA;
	IF kindex(TASK_URL,"iat") THEN DO; TASK_URL = "IAT"; END;
  	ELSE IF kindex(TASK_URL,"debriefing") THEN DO; TASK_URL = "DEBRIEF"; END;
  	ELSE IF kindex(TASK_URL,"concepts") THEN DO; TASK_URL = "CONCEPTS"; END; 
  	ELSE IF kindex(TASK_URL,"explicit") THEN DO; TASK_URL = "EXPLICIT"; END;
PROC SORT DATA=temp2; BY session_id;
PROC transpose DATA=temp2 NAME=name OUT=taskID PREFIX=task; BY SESSION_ID; VAR TASK_URL;ID TASK_NUMBER; 
PROC transpose DATA=temp2 NAME=name OUT=timeID PREFIX=time; BY SESSION_ID; VAR TASK_CREATION_DATE;ID TASK_NUMBER;
PROC SORT DATA=taskID; BY session_id; PROC SORT DATA=timeID; BY session_id;
DATA temp2; MERGE taskID timeID; BY session_ID; DROP _LABEL_ name;
RUN;

DATA web_out.researchsessioninfo; SET temp2;
IF task3 IN (' floweririsb.html', ' floweririsa.html', ' flowerhibiscusb.html', ' flowerhibiscusa.html', ' flowersunflowera.html', ' flowersunflowerb.html', ' flowerlilyb.html', ' flowerlilya.html', ' flowercarnationb.html', ' flowercarnationa.html', ' flowerdaisya.html', ' flowerdaisyb.html', ' flowerorchida.html', ' flowerorchidb.html', ' flowertulipb.html', ' flowertulipa.html', ' flowerrosea.html', ' flowerroseb.html', ' flowerpoppya.html', ' flowerpoppyb.html')  THEN condition = 2;
ELSE IF task3 IN (' posnegmanipatkinsa.html', ' posnegmanipatkinsb.html', ' posnegmanipgottib.html', ' posnegmanipgottia.html', ' posnegmanipdahmera.html', ' posnegmanipdahmerb.html', ' posnegmanipbundyb.html', ' posnegmanipbundya.html', ' posnegmanipyatesb.html', ' posnegmanipyatesa.html', ' posnegmanipkaczynskia.html', ' posnegmanipkaczynskib.html', ' posnegmanipskillinga.html', ' posnegmanipskillingb.html', ' posnegmanipmansonb.html', ' posnegmanipmansona.html', ' posnegmaniphitlerb.html', ' posnegmaniphitlera.html', ' posnegmanipmcveigha.html', ' posnegmanipmcveighb.html') THEN condition = 1;
ELSE IF task3 IN (' insectbeea.html', ' insectbeeb.html', ' insectantb.html', ' insectanta.html', ' insectmosquitoa.html', ' insectmosquitoa.html', ' insectcockroacha.html', ' insectcockroachb.html', ' insectgrasshopperb.html', ' insectgrasshoppera.html', ' insectbeetlea.html', ' insectbeetleb.html', ' insectprayingmantisa.html', ' insectprayingmantisb.html', ' insectdragonflya.html', ' insectdragonflyb.html', ' insectcentipedeb.html', ' insectcentipedea.html', ' insectbutterflya.html', ' insectbutterflyb.html')  THEN condition = 2;
ELSE IF task3 IN (' posnegmanipwoodsb.html', ' posnegmanipwoodsa.html', ' posnegmanipwinfreyb.html', ' posnegmanipwinfreya.html', ' posnegmanipmandelab.html', ' posnegmanipmandelaa.html', ' posnegmanipkingb.html', ' posnegmanipkinga.html', ' posnegmanipcosbya.html', ' posnegmanipcosbyb.html', ' posnegmanipalib.html', ' posnegmanipalia.html', ' posnegmanipmorrisona.html', ' posnegmanipmorrisonb.html', ' posnegmanipjordanb.html', ' posnegmanipjordana.html', ' posnegmanipowensb.html', ' posnegmanipowensa.html', ' posnegmanipwashingtonb.html', ' posnegmanipwashingtona.html') THEN condition = 1;
RUN;


PROC FREQ DATA = web_out.researchsessioninfo; TABLES condition; RUN;


/*Condition 1 = Negative White/Positive Black manipulation = 624;
/*Condition 2 = Control = 610;


/************************************************/
/*                                              */
/*                EXPLICIT DATA                 */
/*                                              */
/************************************************/
DATA web_out.new_researchexplicit; SET web_in.researchexplicit;
	IF question_name = "text" OR question_name = "d" THEN delete; 
	IF question_name = "IMPTASKTO" THEN delete; 
	IF session_id = "1018423" or session_id = "1033896" THEN delete; 
RUN;
PROC SORT; 
by session_id; 
RUN;
PROC transpose DATA= web_out.new_researchexplicit out=web_out.clean_researchexplicit_all; 
by session_id;
id question_name; 
VAR question_response; 
RUN;
/********************************************************/
/*            RECODING DATA INTO NUMERIC DATA           */
/********************************************************/

DATA web_out.clean_researchexplicit_all; SET web_out.clean_researchexplicit_all;
Tblack1 = Tblack * 1;
Twhite1 = Twhite * 1;
attrace1 = attrace * 1;

posmanipking1 = posmanipkinga * 1;
posmanipking2 = posmanipkingb * 1;
posmanipwoods1 = posmanipwoodsa * 1;
posmanipwoods2 = posmanipwoodsb * 1;
posmanipowens1 = posmanipowensa * 1;
posmanipowens2 = posmanipowensb * 1;
posmanipmandela1 = posmanipmandelaa * 1;
posmanipmandela2 = posmanipmandelab * 1;
posmanipmorrison1 = posmanipmorrisona * 1;
posmanipmorrison2 = posmanipmorrisonb * 1;
posmanipwinfrey1 = posmanipwinfreya * 1;
posmanipwinfrey2 = posmanipwinfreyb * 1;
posmanipwashington1 = posmanipwashington * 1;
posmanipwashington2 = posmanipwashington * 1;
posmanipcosby1 = posmanipcosbya * 1;
posmanipcosby2 = posmanipcosbyb * 1;
posmanipali1 = posmanipalia * 1;
posmanipali2 = posmanipalib * 1;
posmanipjordan1 = posmanipjordana * 1;
posmanipjordan2 = posmanipjordanb * 1;

choiceking1 = choicekinga * 1;
choiceking2 = choicekingb * 1;
choicewoods1 = choicewoodsa * 1;
choicewoods2 = choicewoodsb * 1;
choiceowens1 = choiceowensa * 1;
choiceowens2 = choiceowensb * 1;
choicemandela1 = choicemandelaa * 1;
choicemandela2 = choicemandelab * 1;
choicemorrison1 = choicemorrisona * 1;
choicemorrison2 = choicemorrisonb * 1;
choicewinfrey1 = choicewinfreya * 1;
choicewinfrey2 = choicewinfreyb * 1;
choicewashington1 = choicewashingtona * 1;
choicewashington2 = choicewashingtonb * 1;
choicecosby1 = choicecosbya * 1;
choicecosby2 = choicecosbyb * 1;
choiceali1 = choicealia * 1;
choiceali2 = choicealib * 1;
choicejordan1 = choicejordana * 1;
choicejordan2 = choicejordanb * 1;

negmanipgotti1 = negmanipgottia * 1;
negmanipgotti2 = negmanipgottib * 1;
negmanipdahmer1 = negmanipdahmera * 1;
negmanipdahmer2 = negmanipdahmerb * 1;
negmanipmanson1 = negmanipmansona * 1;
negmanipmanson2 = negmanipmansonb * 1;
negmanipmcveigh1 = negmanipmcveigha * 1;
negmanipmcveigh2 = negmanipmcveighb * 1;
negmanipskilling1 = negmanipskillinga * 1;
negmanipskilling2 = negmanipskillingb * 1;
negmanipatkins1 = negmanipatkinsa * 1;
negmanipatkins2 = negmanipatkinsb * 1;
negmanipyates1 = negmanipyatesa * 1;
negmanipyates2 = negmanipyatesb * 1;
negmanipkaczynski1 = negmanipkaczynskia * 1;
negmanipkaczynski2 = negmanipkaczynskib * 1;
negmanipbundy1 = negmanipbundya * 1;
negmanipbundy2 = negmanipbundyb * 1;
negmaniphitler1 = negmaniphitlera * 1;
negmaniphitler2 = negmaniphitlerb * 1;

choicegotti1 = choicegottia * 1;
choicegotti2 = choicegottib * 1;
choicedahmer1 = choicedahmera * 1;
choicedahmer2 = choicedahmerb * 1;
choicemanson1 = choicemansona * 1;
choicemanson2 = choicemansonb * 1;
choicemcveigh1 = choicemcveigha * 1;
choicemcveigh2 = choicemcveighb * 1;
choiceskilling1 = choiceskillinga * 1;
choiceskilling2 = choiceskillingb * 1;
choiceatkins1 = choiceatkinsa * 1;
choiceatkins2 = choiceatkinsb * 1;
choiceyates1 = choiceyatesa * 1;
choiceyates2 = choiceyatesb * 1;
choicekaczynski1 = choicekaczynskia * 1;
choicekaczynski2 = choicekaczynskib * 1;
choicebundy1 = choicebundya * 1;
choicebundy2 = choicebundyb * 1;
choicehitler1 = choicehitlera * 1;
choicehitler2 = choicehitlerb * 1;
choicehitler3 = choicehiltera * 1;
choicehitler4 = choicehilterb * 1;

flowerhibiscus1 = flowerhibiscusa * 1;
flowerhibiscus2 = flowerhibiscusb * 1;
flowerdaisy1 = flowerdaisya * 1;
flowerdaisy2 = flowerdaisyb * 1;
flowerlily1 = flowerlilya * 1;
flowerlily2 = flowerlilyb * 1;
flowerrose1 = flowerosea * 1;
flowerrose2 = flowerroseb * 1;
flowersunflower1 = flowersunflowera * 1;
flowersunflower2 = flowersunflowerb * 1;
flowerorchid1 = flowerorchida * 1;
flowerorchid2 = flowerorchidb * 1;
flowertulip1 = flowertulipa * 1;
flowertulip2 = flowertulipb * 1;
flowercarnation1 = flowercarnationa * 1;
flowercarnation2 = flowercarnationb * 1;
floweriris1 = floweririsa * 1;
floweriris2 = floweririsb * 1;
flowerpoppy1 = flowerpoppya * 1;
flowerpoppy2 = flowerpoppyb * 1;

choicehibiscus1 = choicehibiscusa * 1;
choicehibiscus2 = choicehibiscusb * 1;
choicedaisy1 = choicedaisya * 1;
choicedaisy2 = choicedaisyb * 1;
choicelily1 = choicelilya * 1;
choicelily2 = choicelilyb * 1;
choicerose1 = choicerosea * 1;
choicerose2 = choiceroseb * 1;
choicesunflower1 = choicesunflowera * 1;
choicesunflower2 = choicesunflowerb * 1;
choiceorchid1 = choiceorchida * 1;
choiceorchid2 = choiceorchidb * 1;
choicetulip1 = choicetulipa * 1;
choicetulip2 = choicetulipb * 1;
choicecarnation1 = choicecarnationa * 1;
choicecarnation2 = choicecarnationb * 1;
choiceiris1 = choiceirisa * 1;
choiceiris2 = choiceirisb * 1;
choicepoppy1 = choicepoppya * 1;
choicepoppy2 = choicepoppyb * 1;

insectant1 = insectanta * 1;
insectant2 = insectantb * 1;
insectprayingmantis1 = insectprayingmanti * 1;
insectprayingmantis2 = insectprayingmanti * 1;
insectbee1 = insectbeea * 1;
insectbee2 = insectbeeb * 1;
insectbutterfly1 = insectbutterflya * 1;
insectbutterfly2 = insectbutterflyb * 1;
insectbeetle1 = insectbeetlea * 1;
insectbeetle2 = insectbeetleb * 1;
insectcockroach1 = insectcockroacha * 1;
insectcockroach2 = insectcockroachb * 1;
insectcentipede1 = insectcentipedea * 1;
insectcentipede2 = insectcentipedeb * 1;
insectgrasshopper1 = insectgrasshoppera * 1;
insectgrasshopper2 = insectgrasshopperb * 1;
insectmosquito1 = insectmosquitoa * 1;
insectmosquito2 = insectmosquitob * 1;
insectdragonfly1 = insectdragonflya * 1;
insectdragonfly2 = insectdragonflyb * 1;

choiceant1 = choiceanta * 1;
choiceant2 = choiceantb * 1;
choiceprayingmantis1 = choiceprayingmanti * 1;
choiceprayingmantis2 = choiceprayingmanti * 1;
choicebee1 = choicebeea * 1;
choicebee2 = choicebeeb * 1;
choicebutterfly1 = choicebutterflya * 1;
choicebutterfly2 = choicebutteflyb * 1;
choicebeetle1 = choicebeetlea * 1;
choicebeetle2 = choicebeetleb * 1;
choicecockroach1 = choicecockroacha * 1;
choicecockroach2 = choicecockroachb * 1;
choicecentipede1 = choicecentipedea * 1;
choicecentipede2 = choicecentipedeb * 1;
choicegrasshopper1 = choicegrasshoppera * 1;
choicegrasshopper2 = choicegrasshopperb * 1;
choicemosquito1 = choicemosquitoa * 1;
choicemosquito2 = choicemosquitob * 1;
choicedragonfly1 = choicedragonflya * 1;
choicedragonfly2 = choicedragonflyb * 1;

manip_correct = 0;
IF negmanipbundy1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipbundy2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler1 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler2 = 1 THEN manip_correct = manip_correct + 1;

IF choicebundy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebundy2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegotti1= 1 THEN manip_correct = manip_correct + 1;
IF choicegotti2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson2= 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceyates1= 1 THEN manip_correct = manip_correct + 1;
IF choiceyates2= 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler2 = 1 THEN manip_correct = manip_correct + 1;

IF posmanipking1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipking2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipali1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipali2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceking1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceking2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceali1= 1 THEN manip_correct = manip_correct + 1;
IF choiceali2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison2= 1 THEN manip_correct = manip_correct + 1;
IF choicewoods1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewoods2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecosby1= 1 THEN manip_correct = manip_correct + 1;
IF choicecosby2= 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington2 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan1 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela2 = 1 THEN manip_correct = manip_correct + 1;

IF flowercarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF flowercarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerrose1= 1 THEN manip_correct = manip_correct + 1;
IF flowerrose2 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip1 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip2= 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy1= 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy2= 1 THEN manip_correct = manip_correct + 1;
IF flowerlily1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerlily2 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris1 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris2 = 1 THEN manip_correct = manip_correct + 1;

IF choicecarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF choicerose1= 1 THEN manip_correct = manip_correct + 1;
IF choicerose2 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip1 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip2= 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy1= 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy2= 1 THEN manip_correct = manip_correct + 1;
IF choicelily1 = 1 THEN manip_correct = manip_correct + 1;
IF choicelily2 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris2 = 1 THEN manip_correct = manip_correct + 1;

IF insectant1 = 1 THEN manip_correct = manip_correct + 1;
IF insectant2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbee1= 1 THEN manip_correct = manip_correct + 1;
IF insectbee2 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceant1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceant2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebee1= 1 THEN manip_correct = manip_correct + 1;
IF choicebee2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede2 = 1 THEN manip_correct = manip_correct + 1;
RUN;

DATA web_out.clean_researchexplicit_all; SET web_out.clean_researchexplicit_all;
DROP 
Tblack
Twhite
attrace

posmanipkinga
posmanipkingb
posmanipwoodsa
posmanipwoodsb
posmanipowensa
posmanipowensb
posmanipmandelaa
posmanipmandelab
posmanipmorrisona
posmanipmorrisonb
posmanipwinfreya
posmanipwinfreyb
posmanipwashington
posmanipcosbya
posmanipcosbyb
posmanipalia
posmanipalib
posmanipjordana
posmanipjordanb
choicekinga
choicekingb
choicewoodsa
choicewoodsb
choiceowensa
choiceowensb
choicemandelaa
choicemandelab
choicemorrisona
choicemorrisonb
choicewinfreya
choicewinfreyb
choicewashingtona
choicewashingtonb
choicecosbya
choicecosbyb
choicealia
choicealib
choicejordana
choicejordanb

negmanipgottia
negmanipgottib
negmanipdahmera
negmanipdahmerb
negmaipdahmerb
negmanipmansona
negmanipmansonb
negmanipmcveigha
negmanipmcveighb
negmanipskillinga
negmanipskillingb
negmanipatkinsa
negmanipatkinsb
negmanipyatesa
negmanipyatesb
negmanipkaczynskia
negmanipkaczynskib
negmanipbundya
negmanipbundyb
negmaniphitlera
negmaniphitlerb
choicegottia
choicegottib
choicedahmera
choicedahmerb
choicemansona
choicemansonb
choicemcveigha
choicemcveighb
choiceskillinga
choiceskillingb
choiceatkinsa
choiceatkinsb
choiceyatesa
choiceyatesb
choicekaczynskia
choicekaczynskib
choicebundya
choicebundyb
choicehitlera
choicehitlerb
choicehiltera
choicehilterb

flowerhibiscusa
flowerhibiscusb
flowerdaisya
flowerdaisyb
flowerlilya
flowerlilyb
flowerosea
flowerrosea
flowerroseb
flowersunflowera
flowersunflowerb
flowerorchida
flowerorchidb
flowertulipa
flowertulipb
flowercarnationa
flowercarnationb
floweririsa
floweririsb
flowerpoppya
flowerpoppyb
choicehibiscusa
choicehibiscusb
choicedaisya
choicedaisyb
choicelilya
choicelilyb
choicerosea
choiceroseb
choicesunflowera
choicesunflowerb
choiceorchida
choiceorchidb
choicetulipa
choicetulipb
choicecarnationa
choicecarnationb
choiceirisa
choiceirisb
choicepoppya
choicepoppyb
insectanta
insectantb
insectprayingmanti
insectbeea
insectbeeb
insectbutterflya
insectbutterflyb
insectbeetlea
insectbeetleb
insectcockroacha
insectcockroachb
insectcentipedea
insectcentipedeb
insectgrasshoppera
insectgrasshopperb
insectmosquitoa
insectmosquitob
insectdragonflya
insectdragonflyb
choiceanta
choiceantb
choiceprayingmanti
choicebeea
choicebeeb
choicebutterflya
choicebutterflyb
choicebeetlea
choicebeetleb
choicecockroacha
choicecockroachb
choicecentipedea
choicecentipedeb
choicegrasshoppera
choicegrasshopperb
choicemosquitoa
choicemosquitob
choicedragonflya
choicedragonflyb;
RUN;

/********************************************************/
/*               Looking at Order effects               */
/********************************************************/
PROC SORT DATA = web_in.researchsessiontasks; 
by session_id task_url; 
DATA web_out.researchtaskorder; SET web_in.researchsessiontasks;
repeat=0;
     IF session_id = lag(session_id) and task_url = lag(task_url)
        THEN repeat=1; *IF prior row is same as current row, mark as a repeat;
PROC FREQ; TABLES repeat; RUN; 
DATA web_out.researchtaskorder; SET web_out.researchtaskorder;
    	 IF repeat = 1 THEN delete; DROP repeat; RUN; *DROP duplicate lines of DATA;

PROC FREQ DATA = web_out.researchtaskorder;
TABLES task_url;
RUN;

DATA web_out.researchtaskorder; SET web_out.researchtaskorder;
 *tranwrd looks for the first string in quotes and replaces it with the second string in quotes;
 task_url = tranwrd(task_url,"/common/en-us/html/IATTask.jsp?i=/implicit/user/","");
 task_url = tranwrd(task_url,".html","");
 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
 task_url = tranwrd(task_url,"/user/education/","");
 task_url = tranwrd(task_url,".xml&","");
 task_url = tranwrd(task_url,".jsp","");
 task_url = tranwrd(task_url,".xml","");
 task_url = tranwrd(task_url,"education/race/","");
 task_url = tranwrd(task_url,"/common/en-us/html/","");
RUN;

PROC SORT;
by session_id;
RUN;
PROC MEANS;
CLASS task_url;
VAR task_number;
RUN;
PROC transpose DATA = web_out.researchtaskorder out = web_out.clean_researchtask_order; 
by session_id;
id task_url; 
VAR task_number; 
RUN;

DATA web_out.clean_researchtask_order; SET web_out.clean_researchtask_order;
IF explicit = 44 THEN DO;
   IEorder = 1;
END;
ELSE IF  explicit = 46 THEN DO;
   IEorder = 2;
END;
RUN;

*IEorder = 1 MEANS explicit first;
*IEorder = 2 MEANS implicit first;


/********************************************************/
/*   Merging session with task (to get session_status)  */
/********************************************************/
DATA web_out.researchsessions; SET web_in.researchsessions;
KEEP 
session_id
session_status
user_id;
RUN;
PROC SORT;
by session_id;
RUN;
PROC SORT DATA = web_out.clean_researchtask_order;
by session_id;
RUN;

DATA web_out.clean_researchtask_order;
merge web_out.researchsessions web_out.clean_researchtask_order;
by session_id;
RUN;


/********************************************************/
/*              Merging demo with task_order            */
/********************************************************/

PROC SORT DATA=web_in.researchdemo;
by user_id;
RUN;

PROC transpose DATA = web_in.researchdemo out = web_out.researchdemo_clean; 
by user_id;
id characteristic; 
VAR value; 
RUN;

PROC SORT DATA=web_out.clean_researchtask_order; by user_id;RUN;
PROC SORT DATA=web_out.researchdemo_clean; by user_id;RUN;
DATA web_out.final_researchtask_order;
merge web_out.clean_researchtask_order web_out.researchdemo_clean;
by user_id;
DROP _NAME_;
RUN;

DATA web_out.final_researchtask_order; SET web_out.final_researchtask_order;
birthmonth1 = birthmonth * 1;
birthyear1 = birthyear * 1;
education1 = education * 1;
engfluency1 = engfluency * 1;
ethnicityomb1 = ethnicityomb * 1;
raceomb1 = raceomb * 1;
IF sex = 'f' THEN sex1 = 0;
IF sex = 'm' THEN sex1 = 1;
politicalid1 = politicalid * 1;
religionid1 = religionid * 1;
ethnicity1 = ethnicity * 1;
age = 2008 - birthyear1;

DROP birthmonth ethnicity birthyear education engfluency ethnicityomb religionid sex;
RUN;
PROC FREQ;
TABLES raceomb1;
RUN;

DATA web_out.final_researchtask_order; SET web_out.final_researchtask_order;
KEEP
session_id
session_status
user_id
birthmonth1
birthyear1
education1
engfluency1
ethnicityomb1 
raceomb1 
sex1
politicalid1 
religionid1 
age
IEorder;
RUN;

/********************************************************/
/*   Merging final session info (to get condition)      */
/********************************************************/
PROC SORT DATA = web_out.final_researchtask_order;
by session_id;
RUN;
DATA web_out.researchsessioninfo_final; SET web_out.researchsessioninfo;
KEEP
session_id
condition;
RUN;
DATA web_out.final_researchtask_order;
merge web_out.final_researchtask_order web_out.researchsessioninfo_final;
by session_id;
RUN;

/********************************************************/
/*           DOING FINAL SORT OF ALL FILES              */
/********************************************************/
DATA race.raceiat;
merge 	race.race_iat_clean
		race.pairing(rename=(PB3=RPB3 PB4=RPB4 PB6=RPB6 PB7=RPB7))
		race.ns(rename=(NB3=RNB3 NB4=RNB4 NB6=RNB6 NB7=RNB7));by session_id;
raceiat = IAT;
REB3 = EB3;
REB4 = EB4;
REB6 = EB6;
REB7 = EB7;
R_exclude = subexcl;
KEEP raceiat session_id REB3 REB4 REB6 REB7 RNB3 RNB4 RNB6 RNB7 RPB3 RPB4 RPB6 RPB7 R_exclude;
PROC SORT;
by session_id;
RUN;
DATA final_race_iat; SET race.raceiat;
RUN;

PROC SORT
DATA = final_race_iat;
by session_id;
RUN;
PROC SORT DATA=web_out.clean_researchexplicit_all;
by session_id;
RUN;
PROC SORT
DATA = web_out.final_researchtask_order;
by session_id;
RUN;


PROC contents DATA=final_race_iat;RUN;
PROC contents DATA=web_out.clean_researchexplicit_all;RUN;
PROC contents DATA=web_out.final_researchtask_order;RUN;

/********************************************************/
/*           MERGING ALL DATA TOGETHER                  */
/********************************************************/
DATA web_out.researchfinal;
merge final_race_iat web_out.clean_researchexplicit_all web_out.final_researchtask_order;
by session_id;
RUN;
PROC contents DATA = web_out.researchfinal;
RUN;


/********************************************************/
/*    CHECKING TO MAKE SURE MISSING DATA IS EXPECTED    */
/********************************************************/
PROC MEANS DATA=web_out.researchfinal missing; *We have none in the DATA;
CLASS _ourip;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.researchfinal missing;
CLASS study_name;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.researchfinal missing;
CLASS Condition;
VAR session_id;
RUN;


/********************************************************/
/*             DROPPING SS WHO DIDN'T GET A 0           */
/********************************************************/
DATA web_out.newresearchfinal; SET web_out.researchfinal;
IF R_exclude ne 0 THEN raceiat = .;
RUN;

/********************************************************/
/*         EXAMINING PEOPLE WHO GOT TO VERY END         */
/********************************************************/
DATA web_out.lefinresearch; SET web_out.newresearchfinal;
IF session_status ne 'C' THEN delete;
RUN;

PROC FREQ DATA = web_out.lefinresearch;
TABLES condition;
RUN;

*condition 1 = 520;
*condition 2 = 507;



/********************************************************/
/*     EXAMINING WHO GOT >=30 MANIPULATIONS CORRECT      */
/********************************************************/
DATA web_out.mancheckresearch; SET web_out.lefinresearch;
where manip_correct >= 30;
IF politicalid1 = 1 THEN newpolitical = 1;
IF politicalid1 = 2 THEN newpolitical = 1;
IF politicalid1 = 3 THEN newpolitical = 1;
IF politicalid1 = -1 THEN newpolitical = 0;
IF politicalid1 = -2 THEN newpolitical = 0;
IF politicalid1 = -3 THEN newpolitical = 0;
IF politicalid1 = 0 THEN newpolitical = 3;
newattrace1 = attrace1 - 4;
RUN;

PROC FREQ DATA = web_out.mancheckresearch;
TABLES condition;
RUN;

*condition 1 = 508;
*condition 2 = 506;

/***************************************************/
/* THERE ARE FOUR FINAL DATA SETS                  */
/* 1) final - raw DATA with nobody DROPped         */
/* 2) newfinal - ss with IATs /= 0 DROPped         */
/* 3) lefin - ss not getting a C for the study     */
/* 4) mancheck - only ss >=30 manip questions right*/
/***************************************************/



*CLEANING LAB STUDY;

/************************************************/
/*                                              */
/*        		SETting IAT DATA Up 		    */
/*                                              */
/************************************************/

DATA temp; SET web_in.labimplicit; 
IF BLOCK_NAME in ('BLOCK0', 'BLOCK1', 'BLOCK4') THEN delete;
IF TRIAL_ERROR = '0' THEN TRIALERROR = 0;
ELSE IF TRIAL_ERROR = '1' THEN TRIALERROR = 1;
KEEP trial_number block_name session_ID block_pairing_definition trial_latency trialerror task_name;
RUN;

PROC SORT DATA=temp;
BY session_id task_name block_name trial_number;
RUN;

DATA temp; SET temp;
repeat = 0;
IF session_ID = lag(session_id) and TASK_NAME= lag(TASK_NAME) AND BLOCK_NAME = lag(BLOCK_NAME) AND TRIAL_NUMBER = lag(TRIAL_NUMBER) 
THEN repeat=1; *IF prior row is same as current row, mark as a repeat;

PROC SORT; 
BY session_ID; 
RUN;

PROC FREQ; 
TABLES repeat; 
RUN; 

DATA temp; SET temp;
IF repeat = 1 THEN DELETE; 
DROP repeat; 
RUN; *DROP duplicate lines of DATA;



/************************************************/
/*                                              */
/*        SORTING THROUGH THE IAT              */
/*                                              */
/************************************************/
DATA reordered; SET temp;
IF task_name in ("demo_raceb") THEN DO;
IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B7';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B4';
END;
ELSE IF task_name in ("demo_racea") THEN DO;
	IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B4';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B7';
END;
RUN;



/*************************************************/
/* RACE IAT (Higher scores indicate pro-white) */
/*************************************************/
DATA web_in.race_iat; SET reordered;
WHERE task_name IN ("demo_racea", "demo_raceb");
DROP BLOCK_NAME;
RUN;

%iatCalc(web_in, race, race_iat, race_iat_clean, BLOCK, SESSION_ID, TRIAL_LATENCY, TRIALERROR, 1, 2, 1); 

DATA race.input; SET web_in.race_iat;   *pull up the raw DATASET for use and KEEP only the necessary VARiables;
KEEP trial_number BLOCK block_pairing_definition session_id task_name trialerror trial_latency;

PROC SORT; 
BY session_ID BLOCK;  *SORT by session and block so transpose function will work below;
RUN;

/*identIFying block pairing definitions*/
DATA race.pairing; SET race.input; 
WHERE TRIAL_NUMBER = 1; 
KEEP session_ID BLOCK block_pairing_definition;

PROC TRANSPOSE DATA=race.pairing PREFIX=P NAME=name OUT=race.pairing; 
BY session_ID; 
VAR block_pairing_definition;
ID BLOCK;

PROC SORT DATA=race.PAIRING; 
BY SESSION_ID; 
RUN; *outputs a file with session_id and the block_pairing_defs for all blocks;

/*n per block - including extreme outliers;	VARs=nBLOCK0, nBLOCK, ... ; SET=ns*/
DATA race.ns; SET race.input; KEEP SESSION_ID BLOCK TRIAL_NUMBER;
PROC MEANS DATA=race.ns noprint; BY SESSION_ID BLOCK; VAR TRIAL_NUMBER; OUTPUT OUT=race.MEANS n=N; 
PROC TRANSPOSE DATA=race.MEANS PREFIX=N NAME=name OUT=race.spdMEANS; BY SESSION_ID; ID BLOCK;
PROC SORT DATA=race.spdMEANS; BY SESSION_ID;
DATA race.ns; SET race.spdMEANS; WHERE name='N';
RUN; *outputs a file with the number of actual trials in each block;

/************************************************/
/*                                              */
/*        DIFFERENTATING THE CONDITIONS         */
/*                                              */
/************************************************/

DATA temp2; SET web_in.labsessiontasks; 

PROC SORT; 
BY session_ID task_number task_url;

DATA temp2; SET temp2;
     DROP user_ID task_ID; 
     repeat=0;
	 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
	 task_url = tranwrd(task_url,"/user/brock/","");

     IF SESSION_ID = lag(SESSION_ID) and TASK_NUMBER = lag(TASK_NUMBER)
        and TASK_URL = lag(TASK_URL) THEN repeat=1;
/*
PROC MEANS; CLASS repeat; VAR session_id;RUN;*/

DATA temp2; SET temp2;
    IF repeat = 1 THEN delete;  *DROPping repeat DATA;
	IF kindex(TASK_URL,"iat") THEN DO; TASK_URL = "IAT"; END;
  	ELSE IF kindex(TASK_URL,"debriefing") THEN DO; TASK_URL = "DEBRIEF"; END;
  	ELSE IF kindex(TASK_URL,"concepts") THEN DO; TASK_URL = "CONCEPTS"; END; 
  	ELSE IF kindex(TASK_URL,"explicit") THEN DO; TASK_URL = "EXPLICIT"; END;
PROC SORT DATA=temp2; by session_id;
PROC transpose DATA=temp2 name=name out=taskID prefix=task; by SESSION_ID; VAR TASK_URL;id TASK_NUMBER; 
PROC transpose DATA=temp2 name=name out=timeID prefix=time; by SESSION_ID; VAR TASK_CREATION_DATE;id TASK_NUMBER;
PROC SORT DATA=taskID; by session_id; PROC SORT DATA=timeID; by session_id;
DATA temp2; merge taskID timeID; by session_ID; DROP _LABEL_ name;
RUN;

DATA web_out.labsessioninfo; SET temp2;
IF task3 IN (' floweririsb.html', ' floweririsa.html', ' flowerhibiscusb.html', ' flowerhibiscusa.html', ' flowersunflowera.html', ' flowersunflowerb.html', ' flowerlilyb.html', ' flowerlilya.html', ' flowercarnationb.html', ' flowercarnationa.html', ' flowerdaisya.html', ' flowerdaisyb.html', ' flowerorchida.html', ' flowerorchidb.html', ' flowertulipb.html', ' flowertulipa.html', ' flowerrosea.html', ' flowerroseb.html', ' flowerpoppya.html', ' flowerpoppyb.html')  THEN condition = 4;
ELSE IF task3 IN (' posnegmanipatkinsa.html', ' posnegmanipatkinsb.html', ' posnegmanipgottib.html', ' posnegmanipgottia.html', ' posnegmanipdahmera.html', ' posnegmanipdahmerb.html', ' posnegmanipbundyb.html', ' posnegmanipbundya.html', ' posnegmanipyatesb.html', ' posnegmanipyatesa.html', ' posnegmanipkaczynskia.html', ' posnegmanipkaczynskib.html', ' posnegmanipskillinga.html', ' posnegmanipskillingb.html', ' posnegmanipmansonb.html', ' posnegmanipmansona.html', ' posnegmaniphitlerb.html', ' posnegmaniphitlera.html', ' posnegmanipmcveigha.html', ' posnegmanipmcveighb.html') THEN condition = 3;
ELSE IF task3 IN (' insectbeea.html', ' insectbeeb.html', ' insectantb.html', ' insectanta.html', ' insectmosquitoa.html', ' insectmosquitoa.html', ' insectcockroacha.html', ' insectcockroachb.html', ' insectgrasshopperb.html', ' insectgrasshoppera.html', ' insectbeetlea.html', ' insectbeetleb.html', ' insectprayingmantisa.html', ' insectprayingmantisb.html', ' insectdragonflya.html', ' insectdragonflyb.html', ' insectcentipedeb.html', ' insectcentipedea.html', ' insectbutterflya.html', ' insectbutterflyb.html')  THEN condition = 4;
ELSE IF task3 IN (' posnegmanipwoodsb.html', ' posnegmanipwoodsa.html', ' posnegmanipwinfreyb.html', ' posnegmanipwinfreya.html', ' posnegmanipmandelab.html', ' posnegmanipmandelaa.html', ' posnegmanipkingb.html', ' posnegmanipkinga.html', ' posnegmanipcosbya.html', ' posnegmanipcosbyb.html', ' posnegmanipalib.html', ' posnegmanipalia.html', ' posnegmanipmorrisona.html', ' posnegmanipmorrisonb.html', ' posnegmanipjordanb.html', ' posnegmanipjordana.html', ' posnegmanipowensb.html', ' posnegmanipowensa.html', ' posnegmanipwashingtonb.html', ' posnegmanipwashingtona.html') THEN condition = 3;
RUN;


PROC FREQ DATA = web_out.labsessioninfo; TABLES condition; RUN;


/*Condition 3 = Negative White/Positive Black manipulation = 19;
/*Condition 4 = Control = 23;


/************************************************/
/*                                              */
/*                EXPLICIT DATA                 */
/*                                              */
/************************************************/
DATA web_out.new_labexplicit; SET web_in.labexplicit;
	IF question_name = "text" OR question_name = "d" THEN delete; 
	IF question_name = "IMPTASKTO" THEN delete; 
	IF session_id = "1018423" or session_id = "1033896" THEN delete; 
RUN;
PROC SORT; 
by session_id; 
RUN;
PROC transpose DATA= web_out.new_labexplicit out=web_out.clean_labexplicit_all; 
by session_id;
id question_name; 
VAR question_response; 
RUN;
/********************************************************/
/*            RECODING DATA INTO NUMERIC DATA           */
/********************************************************/

DATA web_out.clean_labexplicit_all; SET web_out.clean_labexplicit_all;
Tblack1 = Tblack * 1;
Twhite1 = Twhite * 1;
attrace1 = attrace * 1;
gENDer1 = gENDer * 1;
age1 = age * 1;
ethnicity1 = ethnicity * 1;
race1 = race * 1;

posmanipking1 = posmanipkinga * 1;
posmanipking2 = posmanipkingb * 1;
posmanipwoods1 = posmanipwoodsa * 1;
posmanipwoods2 = posmanipwoodsb * 1;
posmanipowens1 = posmanipowensa * 1;
posmanipowens2 = posmanipowensb * 1;
posmanipmandela1 = posmanipmandelaa * 1;
posmanipmandela2 = posmanipmandelab * 1;
posmanipmorrison1 = posmanipmorrisona * 1;
posmanipmorrison2 = posmanipmorrisonb * 1;
posmanipwinfrey1 = posmanipwinfreya * 1;
posmanipwinfrey2 = posmanipwinfreyb * 1;
posmanipwashington1 = posmanipwashington * 1;
posmanipwashington2 = posmanipwashington * 1;
posmanipcosby1 = posmanipcosbya * 1;
posmanipcosby2 = posmanipcosbyb * 1;
posmanipali1 = posmanipalia * 1;
posmanipali2 = posmanipalib * 1;
posmanipjordan1 = posmanipjordana * 1;
posmanipjordan2 = posmanipjordanb * 1;

choiceking1 = choicekinga * 1;
choiceking2 = choicekingb * 1;
choicewoods1 = choicewoodsa * 1;
choicewoods2 = choicewoodsb * 1;
choiceowens1 = choiceowensa * 1;
choiceowens2 = choiceowensb * 1;
choicemandela1 = choicemandelaa * 1;
choicemandela2 = choicemandelab * 1;
choicemorrison1 = choicemorrisona * 1;
choicemorrison2 = choicemorrisonb * 1;
choicewinfrey1 = choicewinfreya * 1;
choicewinfrey2 = choicewinfreyb * 1;
choicewashington1 = choicewashingtona * 1;
choicewashington2 = choicewashingtonb * 1;
choicecosby1 = choicecosbya * 1;
choicecosby2 = choicecosbyb * 1;
choiceali1 = choicealia * 1;
choiceali2 = choicealib * 1;
choicejordan1 = choicejordana * 1;
choicejordan2 = choicejordanb * 1;

negmanipgotti1 = negmanipgottia * 1;
negmanipgotti2 = negmanipgottib * 1;
negmanipdahmer1 = negmanipdahmera * 1;
negmanipdahmer2 = negmanipdahmerb * 1;
negmanipmanson1 = negmanipmansona * 1;
negmanipmanson2 = negmanipmansonb * 1;
negmanipmcveigh1 = negmanipmcveigha * 1;
negmanipmcveigh2 = negmanipmcveighb * 1;
negmanipskilling1 = negmanipskillinga * 1;
negmanipskilling2 = negmanipskillingb * 1;
negmanipatkins1 = negmanipatkinsa * 1;
negmanipatkins2 = negmanipatkinsb * 1;
negmanipyates1 = negmanipyatesa * 1;
negmanipyates2 = negmanipyatesb * 1;
negmanipkaczynski1 = negmanipkaczynskia * 1;
negmanipkaczynski2 = negmanipkaczynskib * 1;
negmanipbundy1 = negmanipbundya * 1;
negmanipbundy2 = negmanipbundyb * 1;
negmaniphitler1 = negmaniphitlera * 1;
negmaniphitler2 = negmaniphitlerb * 1;

choicegotti1 = choicegottia * 1;
choicegotti2 = choicegottib * 1;
choicedahmer1 = choicedahmera * 1;
choicedahmer2 = choicedahmerb * 1;
choicemanson1 = choicemansona * 1;
choicemanson2 = choicemansonb * 1;
choicemcveigh1 = choicemcveigha * 1;
choicemcveigh2 = choicemcveighb * 1;
choiceskilling1 = choiceskillinga * 1;
choiceskilling2 = choiceskillingb * 1;
choiceatkins1 = choiceatkinsa * 1;
choiceatkins2 = choiceatkinsb * 1;
choiceyates1 = choiceyatesa * 1;
choiceyates2 = choiceyatesb * 1;
choicekaczynski1 = choicekaczynskia * 1;
choicekaczynski2 = choicekaczynskib * 1;
choicebundy1 = choicebundya * 1;
choicebundy2 = choicebundyb * 1;
choicehitler1 = choicehitlera * 1;
choicehitler2 = choicehitlerb * 1;
choicehitler3 = choicehiltera * 1;
choicehitler4 = choicehilterb * 1;

flowerhibiscus1 = flowerhibiscusa * 1;
flowerhibiscus2 = flowerhibiscusb * 1;
flowerdaisy1 = flowerdaisya * 1;
flowerdaisy2 = flowerdaisyb * 1;
flowerlily1 = flowerlilya * 1;
flowerlily2 = flowerlilyb * 1;
flowerrose1 = flowerosea * 1;
flowerrose2 = flowerroseb * 1;
flowersunflower1 = flowersunflowera * 1;
flowersunflower2 = flowersunflowerb * 1;
flowerorchid1 = flowerorchida * 1;
flowerorchid2 = flowerorchidb * 1;
flowertulip1 = flowertulipa * 1;
flowertulip2 = flowertulipb * 1;
flowercarnation1 = flowercarnationa * 1;
flowercarnation2 = flowercarnationb * 1;
floweriris1 = floweririsa * 1;
floweriris2 = floweririsb * 1;
flowerpoppy1 = flowerpoppya * 1;
flowerpoppy2 = flowerpoppyb * 1;

choicehibiscus1 = choicehibiscusa * 1;
choicehibiscus2 = choicehibiscusb * 1;
choicedaisy1 = choicedaisya * 1;
choicedaisy2 = choicedaisyb * 1;
choicelily1 = choicelilya * 1;
choicelily2 = choicelilyb * 1;
choicerose1 = choicerosea * 1;
choicerose2 = choiceroseb * 1;
choicesunflower1 = choicesunflowera * 1;
choicesunflower2 = choicesunflowerb * 1;
choiceorchid1 = choiceorchida * 1;
choiceorchid2 = choiceorchidb * 1;
choicetulip1 = choicetulipa * 1;
choicetulip2 = choicetulipb * 1;
choicecarnation1 = choicecarnationa * 1;
choicecarnation2 = choicecarnationb * 1;
choiceiris1 = choiceirisa * 1;
choiceiris2 = choiceirisb * 1;
choicepoppy1 = choicepoppya * 1;
choicepoppy2 = choicepoppyb * 1;

insectant1 = insectanta * 1;
insectant2 = insectantb * 1;
insectprayingmantis1 = insectprayingmanti * 1;
insectprayingmantis2 = insectprayingmanti * 1;
insectbee1 = insectbeea * 1;
insectbee2 = insectbeeb * 1;
insectbutterfly1 = insectbutterflya * 1;
insectbutterfly2 = insectbutterflyb * 1;
insectbeetle1 = insectbeetlea * 1;
insectbeetle2 = insectbeetleb * 1;
insectcockroach1 = insectcockroacha * 1;
insectcockroach2 = insectcockroachb * 1;
insectcentipede1 = insectcentipedea * 1;
insectcentipede2 = insectcentipedeb * 1;
insectgrasshopper1 = insectgrasshoppera * 1;
insectgrasshopper2 = insectgrasshopperb * 1;
insectmosquito1 = insectmosquitoa * 1;
insectmosquito2 = insectmosquitob * 1;
insectdragonfly1 = insectdragonflya * 1;
insectdragonfly2 = insectdragonflyb * 1;

choiceant1 = choiceanta * 1;
choiceant2 = choiceantb * 1;
choiceprayingmantis1 = choiceprayingmanti * 1;
choiceprayingmantis2 = choiceprayingmanti * 1;
choicebee1 = choicebeea * 1;
choicebee2 = choicebeeb * 1;
choicebutterfly1 = choicebutterflya * 1;
choicebutterfly2 = choicebutteflyb * 1;
choicebeetle1 = choicebeetlea * 1;
choicebeetle2 = choicebeetleb * 1;
choicecockroach1 = choicecockroacha * 1;
choicecockroach2 = choicecockroachb * 1;
choicecentipede1 = choicecentipedea * 1;
choicecentipede2 = choicecentipedeb * 1;
choicegrasshopper1 = choicegrasshoppera * 1;
choicegrasshopper2 = choicegrasshopperb * 1;
choicemosquito1 = choicemosquitoa * 1;
choicemosquito2 = choicemosquitob * 1;
choicedragonfly1 = choicedragonflya * 1;
choicedragonfly2 = choicedragonflyb * 1;

manip_correct = 0;
IF negmanipbundy1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipbundy2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler1 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler2 = 1 THEN manip_correct = manip_correct + 1;

IF choicebundy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebundy2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegotti1= 1 THEN manip_correct = manip_correct + 1;
IF choicegotti2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson2= 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceyates1= 1 THEN manip_correct = manip_correct + 1;
IF choiceyates2= 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler2 = 1 THEN manip_correct = manip_correct + 1;

IF posmanipking1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipking2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipali1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipali2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceking1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceking2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceali1= 1 THEN manip_correct = manip_correct + 1;
IF choiceali2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison2= 1 THEN manip_correct = manip_correct + 1;
IF choicewoods1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewoods2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecosby1= 1 THEN manip_correct = manip_correct + 1;
IF choicecosby2= 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington2 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan1 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela2 = 1 THEN manip_correct = manip_correct + 1;

IF flowercarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF flowercarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerrose1= 1 THEN manip_correct = manip_correct + 1;
IF flowerrose2 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip1 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip2= 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy1= 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy2= 1 THEN manip_correct = manip_correct + 1;
IF flowerlily1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerlily2 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris1 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris2 = 1 THEN manip_correct = manip_correct + 1;

IF choicecarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF choicerose1= 1 THEN manip_correct = manip_correct + 1;
IF choicerose2 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip1 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip2= 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy1= 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy2= 1 THEN manip_correct = manip_correct + 1;
IF choicelily1 = 1 THEN manip_correct = manip_correct + 1;
IF choicelily2 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris2 = 1 THEN manip_correct = manip_correct + 1;

IF insectant1 = 1 THEN manip_correct = manip_correct + 1;
IF insectant2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbee1= 1 THEN manip_correct = manip_correct + 1;
IF insectbee2 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceant1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceant2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebee1= 1 THEN manip_correct = manip_correct + 1;
IF choicebee2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede2 = 1 THEN manip_correct = manip_correct + 1;
RUN;

DATA web_out.clean_labexplicit_all; SET web_out.clean_labexplicit_all;
DROP 
Tblack
Twhite
attrace
ethnicity
age
race
gENDer

posmanipkinga
posmanipkingb
posmanipwoodsa
posmanipwoodsb
posmanipowensa
posmanipowensb
posmanipmandelaa
posmanipmandelab
posmanipmorrisona
posmanipmorrisonb
posmanipwinfreya
posmanipwinfreyb
posmanipwashington
posmanipcosbya
posmanipcosbyb
posmanipalia
posmanipalib
posmanipjordana
posmanipjordanb
choicekinga
choicekingb
choicewoodsa
choicewoodsb
choiceowensa
choiceowensb
choicemandelaa
choicemandelab
choicemorrisona
choicemorrisonb
choicewinfreya
choicewinfreyb
choicewashingtona
choicewashingtonb
choicecosbya
choicecosbyb
choicealia
choicealib
choicejordana
choicejordanb

negmanipgottia
negmanipgottib
negmanipdahmera
negmanipdahmerb
negmaipdahmerb
negmanipmansona
negmanipmansonb
negmanipmcveigha
negmanipmcveighb
negmanipskillinga
negmanipskillingb
negmanipatkinsa
negmanipatkinsb
negmanipyatesa
negmanipyatesb
negmanipkaczynskia
negmanipkaczynskib
negmanipbundya
negmanipbundyb
negmaniphitlera
negmaniphitlerb
choicegottia
choicegottib
choicedahmera
choicedahmerb
choicemansona
choicemansonb
choicemcveigha
choicemcveighb
choiceskillinga
choiceskillingb
choiceatkinsa
choiceatkinsb
choiceyatesa
choiceyatesb
choicekaczynskia
choicekaczynskib
choicebundya
choicebundyb
choicehitlera
choicehitlerb
choicehiltera
choicehilterb

flowerhibiscusa
flowerhibiscusb
flowerdaisya
flowerdaisyb
flowerlilya
flowerlilyb
flowerosea
flowerrosea
flowerroseb
flowersunflowera
flowersunflowerb
flowerorchida
flowerorchidb
flowertulipa
flowertulipb
flowercarnationa
flowercarnationb
floweririsa
floweririsb
flowerpoppya
flowerpoppyb
choicehibiscusa
choicehibiscusb
choicedaisya
choicedaisyb
choicelilya
choicelilyb
choicerosea
choiceroseb
choicesunflowera
choicesunflowerb
choiceorchida
choiceorchidb
choicetulipa
choicetulipb
choicecarnationa
choicecarnationb
choiceirisa
choiceirisb
choicepoppya
choicepoppyb
insectanta
insectantb
insectprayingmanti
insectbeea
insectbeeb
insectbutterflya
insectbutterflyb
insectbeetlea
insectbeetleb
insectcockroacha
insectcockroachb
insectcentipedea
insectcentipedeb
insectgrasshoppera
insectgrasshopperb
insectmosquitoa
insectmosquitob
insectdragonflya
insectdragonflyb
choiceanta
choiceantb
choiceprayingmanti
choicebeea
choicebeeb
choicebutterflya
choicebutterflyb
choicebeetlea
choicebeetleb
choicecockroacha
choicecockroachb
choicecentipedea
choicecentipedeb
choicegrasshoppera
choicegrasshopperb
choicemosquitoa
choicemosquitob
choicedragonflya
choicedragonflyb;
RUN;

/********************************************************/
/*               Looking at Order effects               */
/********************************************************/
PROC SORT DATA = web_in.labsessiontasks; 
by session_id task_url; 
DATA web_out.labtaskorder; SET web_in.labsessiontasks;
repeat=0;
     IF session_id = lag(session_id) and task_url = lag(task_url)
        THEN repeat=1; *IF prior row is same as current row, mark as a repeat;
PROC FREQ; TABLES repeat; RUN; 
DATA web_out.labtaskorder; SET web_out.labtaskorder;
    	 IF repeat = 1 THEN delete; DROP repeat; RUN; *DROP duplicate lines of DATA;

PROC FREQ DATA = web_out.labtaskorder;
TABLES task_url;
RUN;

DATA web_out.labtaskorder; SET web_out.labtaskorder;
 *tranwrd looks for the first string in quotes and replaces it with the second string in quotes;
 task_url = tranwrd(task_url,"/common/en-us/html/IATTask.jsp?i=/implicit/user/","");
 task_url = tranwrd(task_url,".html","");
 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
 task_url = tranwrd(task_url,"/user/education/","");
 task_url = tranwrd(task_url,".xml&","");
 task_url = tranwrd(task_url,".jsp","");
 task_url = tranwrd(task_url,".xml","");
 task_url = tranwrd(task_url,"education/race/","");
 task_url = tranwrd(task_url,"/common/en-us/html/","");
RUN;

PROC SORT;
by session_id;
RUN;
PROC MEANS;
CLASS task_url;
VAR task_number;
RUN;
PROC transpose DATA = web_out.labtaskorder out = web_out.clean_labtask_order; 
by session_id;
id task_url; 
VAR task_number; 
RUN;

DATA web_out.clean_labtask_order; SET web_out.clean_labtask_order;
IF explicit = 43 THEN DO;
   IEorder = 1;
END;
ELSE IF  explicit = 45 THEN DO;
   IEorder = 2;
END;
RUN;

*IEorder = 1 MEANS explicit first;
*IEorder = 2 MEANS implicit first;


/********************************************************/
/*   Merging session with task (to get session_status)  */
/********************************************************/
DATA web_out.labsessions; SET web_in.labsessions;
KEEP 
session_id
session_status
user_id;
RUN;
PROC SORT;
by session_id;
RUN;
PROC SORT DATA = web_out.clean_labtask_order;
by session_id;
RUN;

DATA web_out.clean_labtask_order;
merge web_out.labsessions web_out.clean_labtask_order;
by session_id;
RUN;


/********************************************************/
/*   Merging final session info (to get condition)      */
/********************************************************/
PROC SORT DATA = web_out.final_labtask_order;
by session_id;
RUN;
DATA web_out.labsessioninfo_final; SET web_out.labsessioninfo;
KEEP
session_id
condition;
RUN;
DATA web_out.final_labtask_order;
merge web_out.clean_labtask_order web_out.labsessioninfo_final;
by session_id;
RUN;

/********************************************************/
/*           DOING FINAL SORT OF ALL FILES              */
/********************************************************/
DATA race.raceiat;
merge 	race.race_iat_clean
		race.pairing(rename=(PB3=RPB3 PB4=RPB4 PB6=RPB6 PB7=RPB7))
		race.ns(rename=(NB3=RNB3 NB4=RNB4 NB6=RNB6 NB7=RNB7));by session_id;
raceiat = IAT;
REB3 = EB3;
REB4 = EB4;
REB6 = EB6;
REB7 = EB7;
R_exclude = subexcl;
KEEP raceiat session_id REB3 REB4 REB6 REB7 RNB3 RNB4 RNB6 RNB7 RPB3 RPB4 RPB6 RPB7 R_exclude;
PROC SORT;
by session_id;
RUN;
DATA final_race_iat; SET race.raceiat;
RUN;

PROC SORT
DATA = final_race_iat;
by session_id;
RUN;
PROC SORT DATA=web_out.clean_labexplicit_all;
by session_id;
RUN;
PROC SORT
DATA = web_out.final_labtask_order;
by session_id;
RUN;


PROC contents DATA=final_race_iat;RUN;
PROC contents DATA=web_out.clean_labexplicit_all;RUN;
PROC contents DATA=web_out.final_labtask_order;RUN;

/********************************************************/
/*           MERGING ALL DATA TOGETHER                  */
/********************************************************/
DATA web_out.labfinal;
merge final_race_iat web_out.clean_labexplicit_all web_out.final_labtask_order;
by session_id;
RUN;
PROC contents DATA = web_out.labfinal;
RUN;


/********************************************************/
/*    CHECKING TO MAKE SURE MISSING DATA IS EXPECTED    */
/********************************************************/
PROC MEANS DATA=web_out.labfinal missing; *We have none in the DATA;
CLASS _ourip;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.labfinal missing;
CLASS study_name;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.labfinal missing;
CLASS Condition;
VAR session_id;
RUN;


/********************************************************/
/*             DROPPING SS WHO DIDN'T GET A 0           */
/********************************************************/
DATA web_out.newlabfinal; SET web_out.labfinal;
IF R_exclude ne 0 THEN raceiat = .;
RUN;

/********************************************************/
/*         EXAMINING PEOPLE WHO GOT TO VERY END         */
/********************************************************/
DATA web_out.lefinlab; SET web_out.newlabfinal;
IF session_status ne 'C' THEN delete;
RUN;

PROC FREQ DATA = web_out.lefinlab;
TABLES condition;
RUN;

*condition 3 = 19;
*condition 4 = 23;



/********************************************************/
/*     EXAMINING WHO GOT >=30 MANIPULATIONS CORRECT      */
/********************************************************/
DATA web_out.manchecklab; SET web_out.lefinlab;
where manip_correct >= 30;
newattrace1 = attrace1 - 4;
RUN;

PROC FREQ DATA = web_out.manchecklab;
TABLES condition;
RUN;

*condition 3 = 19;
*condition 4 = 23;


*CLEANING HOME STUDY;

/************************************************/
/*                                              */
/*        		SETting IAT DATA Up 		    */
/*                                              */
/************************************************/

DATA temp; SET web_in.homeimplicit; 
IF BLOCK_NAME in ('BLOCK0', 'BLOCK1', 'BLOCK4') THEN delete;
IF TRIAL_ERROR = '0' THEN TRIALERROR = 0;
ELSE IF TRIAL_ERROR = '1' THEN TRIALERROR = 1;
KEEP trial_number block_name session_ID block_pairing_definition trial_latency trialerror task_name;
RUN;

PROC SORT DATA=temp;
BY session_id task_name block_name trial_number;
RUN;

DATA temp; SET temp;
repeat = 0;
IF session_ID = lag(session_id) and TASK_NAME= lag(TASK_NAME) AND BLOCK_NAME = lag(BLOCK_NAME) AND TRIAL_NUMBER = lag(TRIAL_NUMBER) 
THEN repeat=1; *IF prior row is same as current row, mark as a repeat;

PROC SORT; 
BY session_ID; 
RUN;

PROC FREQ; 
TABLES repeat; 
RUN; 

DATA temp; SET temp;
IF repeat = 1 THEN DELETE; 
DROP repeat; 
RUN; *DROP duplicate lines of DATA;



/************************************************/
/*                                              */
/*        SORTING THROUGH THE IAT              */
/*                                              */
/************************************************/
DATA reordered; SET temp;
IF task_name in ("demo_raceb") THEN DO;
IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B7';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B4';
END;
ELSE IF task_name in ("demo_racea") THEN DO;
	IF BLOCK_NAME in ('BLOCK2') THEN BLOCK = 'B3';
	ELSE IF BLOCK_NAME in ('BLOCK3') THEN BLOCK = 'B4';
	ELSE IF BLOCK_NAME in ('BLOCK5') THEN BLOCK = 'B6';
	ELSE IF BLOCK_NAME in ('BLOCK6') THEN BLOCK = 'B7';
END;
RUN;



/*************************************************/
/* RACE IAT (Higher scores indicate pro-white) */
/*************************************************/
DATA web_in.race_iat; SET reordered;
WHERE task_name IN ("demo_racea", "demo_raceb");
DROP BLOCK_NAME;
RUN;

%iatCalc(web_in, race, race_iat, race_iat_clean, BLOCK, SESSION_ID, TRIAL_LATENCY, TRIALERROR, 1, 2, 1); 

DATA race.input; SET web_in.race_iat;   *pull up the raw DATASET for use and KEEP only the necessary VARiables;
KEEP trial_number BLOCK block_pairing_definition session_id task_name trialerror trial_latency;

PROC SORT; 
BY session_ID BLOCK;  *SORT by session and block so transpose function will work below;
RUN;

/*identIFying block pairing definitions*/
DATA race.pairing; SET race.input; 
WHERE TRIAL_NUMBER = 1; 
KEEP session_ID BLOCK block_pairing_definition;

PROC TRANSPOSE DATA=race.pairing PREFIX=P NAME=name OUT=race.pairing; 
BY session_ID; 
VAR block_pairing_definition;
ID BLOCK;

PROC SORT DATA=race.PAIRING; 
BY SESSION_ID; 
RUN; *outputs a file with session_id and the block_pairing_defs for all blocks;

/*n per block - including extreme outliers;	VARs=nBLOCK0, nBLOCK, ... ; SET=ns*/
DATA race.ns; SET race.input; KEEP SESSION_ID BLOCK TRIAL_NUMBER;
PROC MEANS DATA=race.ns noprint; BY SESSION_ID BLOCK; VAR TRIAL_NUMBER; OUTPUT OUT=race.MEANS n=N; 
PROC TRANSPOSE DATA=race.MEANS PREFIX=N NAME=name OUT=race.spdMEANS; BY SESSION_ID; ID BLOCK;
PROC SORT DATA=race.spdMEANS; BY SESSION_ID;
DATA race.ns; SET race.spdMEANS; WHERE name='N';
RUN; *outputs a file with the number of actual trials in each block;

/************************************************/
/*                                              */
/*        DIFFERENTATING THE CONDITIONS         */
/*                                              */
/************************************************/

DATA temp2; SET web_in.homesessiontasks; 

PROC SORT; 
BY session_ID task_number task_url;

DATA temp2; SET temp2;
     DROP user_ID task_ID; 
     repeat=0;
	 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
	 task_url = tranwrd(task_url,"/user/jjoy/","");

     IF SESSION_ID = lag(SESSION_ID) and TASK_NUMBER = lag(TASK_NUMBER)
        and TASK_URL = lag(TASK_URL) THEN repeat=1;
/*
PROC MEANS; CLASS repeat; VAR session_id;RUN;*/

DATA temp2; SET temp2;
    IF repeat = 1 THEN delete;  *DROPping repeat DATA;
	IF kindex(TASK_URL,"iat") THEN DO; TASK_URL = "IAT"; END;
  	ELSE IF kindex(TASK_URL,"debriefing") THEN DO; TASK_URL = "DEBRIEF"; END;
  	ELSE IF kindex(TASK_URL,"concepts") THEN DO; TASK_URL = "CONCEPTS"; END; 
  	ELSE IF kindex(TASK_URL,"explicit") THEN DO; TASK_URL = "EXPLICIT"; END;
PROC SORT DATA=temp2; by session_id;
PROC transpose DATA=temp2 name=name out=taskID prefix=task; by SESSION_ID; VAR TASK_URL;id TASK_NUMBER; 
PROC transpose DATA=temp2 name=name out=timeID prefix=time; by SESSION_ID; VAR TASK_CREATION_DATE;id TASK_NUMBER;
PROC SORT DATA=taskID; by session_id; PROC SORT DATA=timeID; by session_id;
DATA temp2; merge taskID timeID; by session_ID; DROP _LABEL_ name;
RUN;

DATA web_out.homesessioninfo; SET temp2;
IF task3 IN (' floweririsb.html', ' floweririsa.html', ' flowerhibiscusb.html', ' flowerhibiscusa.html', ' flowersunflowera.html', ' flowersunflowerb.html', ' flowerlilyb.html', ' flowerlilya.html', ' flowercarnationb.html', ' flowercarnationa.html', ' flowerdaisya.html', ' flowerdaisyb.html', ' flowerorchida.html', ' flowerorchidb.html', ' flowertulipb.html', ' flowertulipa.html', ' flowerrosea.html', ' flowerroseb.html', ' flowerpoppya.html', ' flowerpoppyb.html')  THEN condition = 6;
ELSE IF task3 IN (' posnegmanipatkinsa.html', ' posnegmanipatkinsb.html', ' posnegmanipgottib.html', ' posnegmanipgottia.html', ' posnegmanipdahmera.html', ' posnegmanipdahmerb.html', ' posnegmanipbundyb.html', ' posnegmanipbundya.html', ' posnegmanipyatesb.html', ' posnegmanipyatesa.html', ' posnegmanipkaczynskia.html', ' posnegmanipkaczynskib.html', ' posnegmanipskillinga.html', ' posnegmanipskillingb.html', ' posnegmanipmansonb.html', ' posnegmanipmansona.html', ' posnegmaniphitlerb.html', ' posnegmaniphitlera.html', ' posnegmanipmcveigha.html', ' posnegmanipmcveighb.html') THEN condition = 5;
ELSE IF task3 IN (' insectbeea.html', ' insectbeeb.html', ' insectantb.html', ' insectanta.html', ' insectmosquitoa.html', ' insectmosquitoa.html', ' insectcockroacha.html', ' insectcockroachb.html', ' insectgrasshopperb.html', ' insectgrasshoppera.html', ' insectbeetlea.html', ' insectbeetleb.html', ' insectprayingmantisa.html', ' insectprayingmantisb.html', ' insectdragonflya.html', ' insectdragonflyb.html', ' insectcentipedeb.html', ' insectcentipedea.html', ' insectbutterflya.html', ' insectbutterflyb.html')  THEN condition = 6;
ELSE IF task3 IN (' posnegmanipwoodsb.html', ' posnegmanipwoodsa.html', ' posnegmanipwinfreyb.html', ' posnegmanipwinfreya.html', ' posnegmanipmandelab.html', ' posnegmanipmandelaa.html', ' posnegmanipkingb.html', ' posnegmanipkinga.html', ' posnegmanipcosbya.html', ' posnegmanipcosbyb.html', ' posnegmanipalib.html', ' posnegmanipalia.html', ' posnegmanipmorrisona.html', ' posnegmanipmorrisonb.html', ' posnegmanipjordanb.html', ' posnegmanipjordana.html', ' posnegmanipowensb.html', ' posnegmanipowensa.html', ' posnegmanipwashingtonb.html', ' posnegmanipwashingtona.html') THEN condition = 5;
RUN;

DATA web_out.homesessioninfo; SET web_out.homesessioninfo;
IF (session_id = "1019830" or session_id = "1019838" or session_id = "1019843" or session_id = "1019848" or session_id = "1016725" or session_id = "1018364" or session_id = "1027220" 
or session_id = "1019849" or session_id = "1021403" or session_id = "1018379" or session_id = "1018387" or session_id = "1018415" or session_id = "1025349" or session_id = "1025404" or session_id = "1027219"
or session_id = "1027219" or session_id = "1025320" or session_id = "1031479" or session_id = "1034646" or session_id = "1034609" or session_id = "1030653" or session_id = "1023170"
or session_id = "1025254" or session_id = "1020667" or session_id = "1020650" or session_id = "1020616" or session_id = "1026640" or session_id = "1026574" or session_id = "1026592" or session_id = "1023234" 
or session_id = "1038378" or session_id = "1038413" or session_id = "1049759" or session_id = "1037616" or session_id = "1036471"
or session_id = "1036499" or session_id = "1036510" or session_id = "1038358" or session_id = "1036552" or session_id = "1020618" or session_id = "1028876" or session_id = "1031543" 
or session_id = "1028905" or session_id = "1030727" or session_id = "1030677" or session_id = "1030685" or session_id = "1028917" or session_id = "1048279"
or session_id = "1032317" or session_id = "1028947" or session_id = "1031449" or session_id = "1051045" or session_id = "1048252" or session_id = "1019871") and condition = 6
THEN ncondition = 4;
RUN;

DATA web_out.homesessioninfo; SET web_out.homesessioninfo;
IF (session_id = "1019830" or session_id = "1019838" or session_id = "1019843" or session_id = "1019848" or session_id = "1016725" or session_id = "1018364" or session_id = "1027220" 
or session_id = "1019849" or session_id = "1021403" or session_id = "1018379" or session_id = "1018387" or session_id = "1018415" or session_id = "1025349" or session_id = "1025404" or session_id = "1027219"
or session_id = "1027219" or session_id = "1025320" or session_id = "1031479" or session_id = "1034646" or session_id = "1034609" or session_id = "1030653" or session_id = "1023170"
or session_id = "1025254" or session_id = "1020667" or session_id = "1020650" or session_id = "1020616" or session_id = "1026640" or session_id = "1026592" 
or session_id = "1026574" or session_id = "1023234" or session_id = "1038378" or session_id = "1038413" or session_id = "1049759" or session_id = "1037616" or session_id = "1036471"
or session_id = "1036499" or session_id = "1036510" or session_id = "1038358" or session_id = "1036552" or session_id = "1020618" or session_id = "1028876" or session_id = "1031543" 
or session_id = "1028905" or session_id = "1030727" or session_id = "1030677" or session_id = "1030685" or session_id = "1028917" or session_id = "1048279"
or session_id = "1032317" or session_id = "1028947" or session_id = "1031449" or session_id = "1051045" or session_id = "1048252" or session_id = "1019871") and condition = 5
THEN ncondition = 3;
RUN;

DATA web_out.homesessioninfo; SET web_out.homesessioninfo;
IF ncondition = 4 THEN condition = 4;
ELSE IF ncondition = 3 THEN condition = 3;
DROP ncondition;
RUN;

PROC FREQ DATA = web_out.homesessioninfo; TABLES condition; RUN;

/*Condition 3 = Negative White/Positive Black manipulation = 19;
/*Condition 4 = Control = 18;
/*Condition 5 = Negative White/Positive Black manipulation = 49;
/*Condition 6 = Control = 56;


/************************************************/
/*                                              */
/*                EXPLICIT DATA                 */
/*                                              */
/************************************************/
DATA web_out.new_homeexplicit; SET web_in.homeexplicit;
	IF question_name = "text" OR question_name = "d" THEN delete; 
	IF question_name = "IMPTASKTO" THEN delete; 
	IF session_id = "1015561" or session_id = "1042748" THEN delete; 
RUN;
PROC SORT; 
by session_id; 
RUN;
PROC transpose DATA= web_out.new_homeexplicit out=web_out.clean_homeexplicit_all; 
by session_id;
id question_name; 
VAR question_response; 
RUN;

/********************************************************/
/*            RECODING DATA INTO NUMERIC DATA           */
/********************************************************/

DATA web_out.clean_homeexplicit_all; SET web_out.clean_homeexplicit_all;
Tblack1 = Tblack * 1;
Twhite1 = Twhite * 1;
attrace1 = attrace * 1;
gENDer1 = gENDer * 1;
age1 = age * 1;
ethnicity1 = ethnicity * 1;
race1 = race * 1;

posmanipking1 = posmanipkinga * 1;
posmanipking2 = posmanipkingb * 1;
posmanipwoods1 = posmanipwoodsa * 1;
posmanipwoods2 = posmanipwoodsb * 1;
posmanipowens1 = posmanipowensa * 1;
posmanipowens2 = posmanipowensb * 1;
posmanipmandela1 = posmanipmandelaa * 1;
posmanipmandela2 = posmanipmandelab * 1;
posmanipmorrison1 = posmanipmorrisona * 1;
posmanipmorrison2 = posmanipmorrisonb * 1;
posmanipwinfrey1 = posmanipwinfreya * 1;
posmanipwinfrey2 = posmanipwinfreyb * 1;
posmanipwashington1 = posmanipwashington * 1;
posmanipwashington2 = posmanipwashington * 1;
posmanipcosby1 = posmanipcosbya * 1;
posmanipcosby2 = posmanipcosbyb * 1;
posmanipali1 = posmanipalia * 1;
posmanipali2 = posmanipalib * 1;
posmanipjordan1 = posmanipjordana * 1;
posmanipjordan2 = posmanipjordanb * 1;

choiceking1 = choicekinga * 1;
choiceking2 = choicekingb * 1;
choicewoods1 = choicewoodsa * 1;
choicewoods2 = choicewoodsb * 1;
choiceowens1 = choiceowensa * 1;
choiceowens2 = choiceowensb * 1;
choicemandela1 = choicemandelaa * 1;
choicemandela2 = choicemandelab * 1;
choicemorrison1 = choicemorrisona * 1;
choicemorrison2 = choicemorrisonb * 1;
choicewinfrey1 = choicewinfreya * 1;
choicewinfrey2 = choicewinfreyb * 1;
choicewashington1 = choicewashingtona * 1;
choicewashington2 = choicewashingtonb * 1;
choicecosby1 = choicecosbya * 1;
choicecosby2 = choicecosbyb * 1;
choiceali1 = choicealia * 1;
choiceali2 = choicealib * 1;
choicejordan1 = choicejordana * 1;
choicejordan2 = choicejordanb * 1;

negmanipgotti1 = negmanipgottia * 1;
negmanipgotti2 = negmanipgottib * 1;
negmanipdahmer1 = negmanipdahmera * 1;
negmanipdahmer2 = negmanipdahmerb * 1;
negmanipmanson1 = negmanipmansona * 1;
negmanipmanson2 = negmanipmansonb * 1;
negmanipmcveigh1 = negmanipmcveigha * 1;
negmanipmcveigh2 = negmanipmcveighb * 1;
negmanipskilling1 = negmanipskillinga * 1;
negmanipskilling2 = negmanipskillingb * 1;
negmanipatkins1 = negmanipatkinsa * 1;
negmanipatkins2 = negmanipatkinsb * 1;
negmanipyates1 = negmanipyatesa * 1;
negmanipyates2 = negmanipyatesb * 1;
negmanipkaczynski1 = negmanipkaczynskia * 1;
negmanipkaczynski2 = negmanipkaczynskib * 1;
negmanipbundy1 = negmanipbundya * 1;
negmanipbundy2 = negmanipbundyb * 1;
negmaniphitler1 = negmaniphitlera * 1;
negmaniphitler2 = negmaniphitlerb * 1;

choicegotti1 = choicegottia * 1;
choicegotti2 = choicegottib * 1;
choicedahmer1 = choicedahmera * 1;
choicedahmer2 = choicedahmerb * 1;
choicemanson1 = choicemansona * 1;
choicemanson2 = choicemansonb * 1;
choicemcveigh1 = choicemcveigha * 1;
choicemcveigh2 = choicemcveighb * 1;
choiceskilling1 = choiceskillinga * 1;
choiceskilling2 = choiceskillingb * 1;
choiceatkins1 = choiceatkinsa * 1;
choiceatkins2 = choiceatkinsb * 1;
choiceyates1 = choiceyatesa * 1;
choiceyates2 = choiceyatesb * 1;
choicekaczynski1 = choicekaczynskia * 1;
choicekaczynski2 = choicekaczynskib * 1;
choicebundy1 = choicebundya * 1;
choicebundy2 = choicebundyb * 1;
choicehitler1 = choicehitlera * 1;
choicehitler2 = choicehitlerb * 1;
choicehitler3 = choicehiltera * 1;
choicehitler4 = choicehilterb * 1;

flowerhibiscus1 = flowerhibiscusa * 1;
flowerhibiscus2 = flowerhibiscusb * 1;
flowerdaisy1 = flowerdaisya * 1;
flowerdaisy2 = flowerdaisyb * 1;
flowerlily1 = flowerlilya * 1;
flowerlily2 = flowerlilyb * 1;
flowerrose1 = flowerosea * 1;
flowerrose2 = flowerroseb * 1;
flowersunflower1 = flowersunflowera * 1;
flowersunflower2 = flowersunflowerb * 1;
flowerorchid1 = flowerorchida * 1;
flowerorchid2 = flowerorchidb * 1;
flowertulip1 = flowertulipa * 1;
flowertulip2 = flowertulipb * 1;
flowercarnation1 = flowercarnationa * 1;
flowercarnation2 = flowercarnationb * 1;
floweriris1 = floweririsa * 1;
floweriris2 = floweririsb * 1;
flowerpoppy1 = flowerpoppya * 1;
flowerpoppy2 = flowerpoppyb * 1;

choicehibiscus1 = choicehibiscusa * 1;
choicehibiscus2 = choicehibiscusb * 1;
choicedaisy1 = choicedaisya * 1;
choicedaisy2 = choicedaisyb * 1;
choicelily1 = choicelilya * 1;
choicelily2 = choicelilyb * 1;
choicerose1 = choicerosea * 1;
choicerose2 = choiceroseb * 1;
choicesunflower1 = choicesunflowera * 1;
choicesunflower2 = choicesunflowerb * 1;
choiceorchid1 = choiceorchida * 1;
choiceorchid2 = choiceorchidb * 1;
choicetulip1 = choicetulipa * 1;
choicetulip2 = choicetulipb * 1;
choicecarnation1 = choicecarnationa * 1;
choicecarnation2 = choicecarnationb * 1;
choiceiris1 = choiceirisa * 1;
choiceiris2 = choiceirisb * 1;
choicepoppy1 = choicepoppya * 1;
choicepoppy2 = choicepoppyb * 1;

insectant1 = insectanta * 1;
insectant2 = insectantb * 1;
insectprayingmantis1 = insectprayingmanti * 1;
insectprayingmantis2 = insectprayingmanti * 1;
insectbee1 = insectbeea * 1;
insectbee2 = insectbeeb * 1;
insectbutterfly1 = insectbutterflya * 1;
insectbutterfly2 = insectbutterflyb * 1;
insectbeetle1 = insectbeetlea * 1;
insectbeetle2 = insectbeetleb * 1;
insectcockroach1 = insectcockroacha * 1;
insectcockroach2 = insectcockroachb * 1;
insectcentipede1 = insectcentipedea * 1;
insectcentipede2 = insectcentipedeb * 1;
insectgrasshopper1 = insectgrasshoppera * 1;
insectgrasshopper2 = insectgrasshopperb * 1;
insectmosquito1 = insectmosquitoa * 1;
insectmosquito2 = insectmosquitob * 1;
insectdragonfly1 = insectdragonflya * 1;
insectdragonfly2 = insectdragonflyb * 1;

choiceant1 = choiceanta * 1;
choiceant2 = choiceantb * 1;
choiceprayingmantis1 = choiceprayingmanti * 1;
choiceprayingmantis2 = choiceprayingmanti * 1;
choicebee1 = choicebeea * 1;
choicebee2 = choicebeeb * 1;
choicebutterfly1 = choicebutterflya * 1;
choicebutterfly2 = choicebutteflyb * 1;
choicebeetle1 = choicebeetlea * 1;
choicebeetle2 = choicebeetleb * 1;
choicecockroach1 = choicecockroacha * 1;
choicecockroach2 = choicecockroachb * 1;
choicecentipede1 = choicecentipedea * 1;
choicecentipede2 = choicecentipedeb * 1;
choicegrasshopper1 = choicegrasshoppera * 1;
choicegrasshopper2 = choicegrasshopperb * 1;
choicemosquito1 = choicemosquitoa * 1;
choicemosquito2 = choicemosquitob * 1;
choicedragonfly1 = choicedragonflya * 1;
choicedragonfly2 = choicedragonflyb * 1;

manip_correct = 0;
IF negmanipbundy1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipbundy2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipgotti2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmanson2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates1= 1 THEN manip_correct = manip_correct + 1;
IF negmanipyates2= 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipmcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipdahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF negmanipkaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler1 = 1 THEN manip_correct = manip_correct + 1;
IF negmaniphitler2 = 1 THEN manip_correct = manip_correct + 1;

IF choicebundy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebundy2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegotti1= 1 THEN manip_correct = manip_correct + 1;
IF choicegotti2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemanson2= 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceatkins2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceyates1= 1 THEN manip_correct = manip_correct + 1;
IF choiceyates2= 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemcveigh2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceskilling2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedahmer2 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski1 = 1 THEN manip_correct = manip_correct + 1;
IF choicekaczynski2 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehitler2 = 1 THEN manip_correct = manip_correct + 1;

IF posmanipking1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipking2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipali1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipali2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmorrison2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwoods2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby1= 1 THEN manip_correct = manip_correct + 1;
IF posmanipcosby2= 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipwashington2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipjordan2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipowens2 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela1 = 1 THEN manip_correct = manip_correct + 1;
IF posmanipmandela2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceking1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceking2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceali1= 1 THEN manip_correct = manip_correct + 1;
IF choiceali2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemorrison2= 1 THEN manip_correct = manip_correct + 1;
IF choicewoods1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewoods2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecosby1= 1 THEN manip_correct = manip_correct + 1;
IF choicecosby2= 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewinfrey2 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington1 = 1 THEN manip_correct = manip_correct + 1;
IF choicewashington2 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan1 = 1 THEN manip_correct = manip_correct + 1;
IF choicejordan2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceowens2 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemandela2 = 1 THEN manip_correct = manip_correct + 1;

IF flowercarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF flowercarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerrose1= 1 THEN manip_correct = manip_correct + 1;
IF flowerrose2 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip1 = 1 THEN manip_correct = manip_correct + 1;
IF flowertulip2= 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerhibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy1= 1 THEN manip_correct = manip_correct + 1;
IF flowerpoppy2= 1 THEN manip_correct = manip_correct + 1;
IF flowerlily1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerlily2 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF flowersunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerdaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF flowerorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris1 = 1 THEN manip_correct = manip_correct + 1;
IF floweriris2 = 1 THEN manip_correct = manip_correct + 1;

IF choicecarnation1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecarnation2 = 1 THEN manip_correct = manip_correct + 1;
IF choicerose1= 1 THEN manip_correct = manip_correct + 1;
IF choicerose2 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip1 = 1 THEN manip_correct = manip_correct + 1;
IF choicetulip2= 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus1 = 1 THEN manip_correct = manip_correct + 1;
IF choicehibiscus2 = 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy1= 1 THEN manip_correct = manip_correct + 1;
IF choicepoppy2= 1 THEN manip_correct = manip_correct + 1;
IF choicelily1 = 1 THEN manip_correct = manip_correct + 1;
IF choicelily2 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower1 = 1 THEN manip_correct = manip_correct + 1;
IF choicesunflower2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedaisy2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceorchid2 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceiris2 = 1 THEN manip_correct = manip_correct + 1;

IF insectant1 = 1 THEN manip_correct = manip_correct + 1;
IF insectant2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbee1= 1 THEN manip_correct = manip_correct + 1;
IF insectbee2 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF insectgrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF insectprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF insectbutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF insectmosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF insectbeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF insectdragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF insectcentipede2 = 1 THEN manip_correct = manip_correct + 1;

IF choiceant1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceant2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebee1= 1 THEN manip_correct = manip_correct + 1;
IF choicebee2 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper1 = 1 THEN manip_correct = manip_correct + 1;
IF choicegrasshopper2= 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis1 = 1 THEN manip_correct = manip_correct + 1;
IF choiceprayingmantis2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly1= 1 THEN manip_correct = manip_correct + 1;
IF choicebutterfly2= 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito1 = 1 THEN manip_correct = manip_correct + 1;
IF choicemosquito2 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle1 = 1 THEN manip_correct = manip_correct + 1;
IF choicebeetle2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecockroach2 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly1 = 1 THEN manip_correct = manip_correct + 1;
IF choicedragonfly2 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede1 = 1 THEN manip_correct = manip_correct + 1;
IF choicecentipede2 = 1 THEN manip_correct = manip_correct + 1;
RUN;

DATA web_out.clean_homeexplicit_all; SET web_out.clean_homeexplicit_all;
DROP 
Tblack
Twhite
attrace
ethnicity
age
race
gENDer

posmanipkinga
posmanipkingb
posmanipwoodsa
posmanipwoodsb
posmanipowensa
posmanipowensb
posmanipmandelaa
posmanipmandelab
posmanipmorrisona
posmanipmorrisonb
posmanipwinfreya
posmanipwinfreyb
posmanipwashington
posmanipcosbya
posmanipcosbyb
posmanipalia
posmanipalib
posmanipjordana
posmanipjordanb
choicekinga
choicekingb
choicewoodsa
choicewoodsb
choiceowensa
choiceowensb
choicemandelaa
choicemandelab
choicemorrisona
choicemorrisonb
choicewinfreya
choicewinfreyb
choicewashingtona
choicewashingtonb
choicecosbya
choicecosbyb
choicealia
choicealib
choicejordana
choicejordanb

negmanipgottia
negmanipgottib
negmanipdahmera
negmanipdahmerb
negmaipdahmerb
negmanipmansona
negmanipmansonb
negmanipmcveigha
negmanipmcveighb
negmanipskillinga
negmanipskillingb
negmanipatkinsa
negmanipatkinsb
negmanipyatesa
negmanipyatesb
negmanipkaczynskia
negmanipkaczynskib
negmanipbundya
negmanipbundyb
negmaniphitlera
negmaniphitlerb
choicegottia
choicegottib
choicedahmera
choicedahmerb
choicemansona
choicemansonb
choicemcveigha
choicemcveighb
choiceskillinga
choiceskillingb
choiceatkinsa
choiceatkinsb
choiceyatesa
choiceyatesb
choicekaczynskia
choicekaczynskib
choicebundya
choicebundyb
choicehitlera
choicehitlerb
choicehiltera
choicehilterb

flowerhibiscusa
flowerhibiscusb
flowerdaisya
flowerdaisyb
flowerlilya
flowerlilyb
flowerosea
flowerrosea
flowerroseb
flowersunflowera
flowersunflowerb
flowerorchida
flowerorchidb
flowertulipa
flowertulipb
flowercarnationa
flowercarnationb
floweririsa
floweririsb
flowerpoppya
flowerpoppyb
choicehibiscusa
choicehibiscusb
choicedaisya
choicedaisyb
choicelilya
choicelilyb
choicerosea
choiceroseb
choicesunflowera
choicesunflowerb
choiceorchida
choiceorchidb
choicetulipa
choicetulipb
choicecarnationa
choicecarnationb
choiceirisa
choiceirisb
choicepoppya
choicepoppyb
insectanta
insectantb
insectprayingmanti
insectbeea
insectbeeb
insectbutterflya
insectbutterflyb
insectbeetlea
insectbeetleb
insectcockroacha
insectcockroachb
insectcentipedea
insectcentipedeb
insectgrasshoppera
insectgrasshopperb
insectmosquitoa
insectmosquitob
insectdragonflya
insectdragonflyb
choiceanta
choiceantb
choiceprayingmanti
choicebeea
choicebeeb
choicebutterflya
choicebutterflyb
choicebeetlea
choicebeetleb
choicecockroacha
choicecockroachb
choicecentipedea
choicecentipedeb
choicegrasshoppera
choicegrasshopperb
choicemosquitoa
choicemosquitob
choicedragonflya
choicedragonflyb;
RUN;


/********************************************************/
/*               Looking at Order effects               */
/********************************************************/
PROC SORT DATA = web_in.homesessiontasks; 
BY session_id task_url; 
DATA web_out.hometaskorder; SET web_in.homesessiontasks;
repeat=0;
     IF session_id = lag(session_id) and task_url = lag(task_url)
        THEN repeat=1; *IF prior row is same as current row, mark as a repeat;
PROC FREQ; TABLES repeat; RUN; 
DATA web_out.hometaskorder; SET web_out.hometaskorder;
    	 IF repeat = 1 THEN delete; DROP repeat; RUN; *DROP duplicate lines of DATA;

PROC FREQ DATA = web_out.hometaskorder;
TABLES task_url;
RUN;

DATA web_out.hometaskorder; SET web_out.hometaskorder;
 *tranwrd looks for the first string in quotes and replaces it with the second string in quotes;
 task_url = tranwrd(task_url,"/common/en-us/html/IATTask.jsp?i=/implicit/user/","");
 task_url = tranwrd(task_url,".html","");
 task_url = tranwrd(task_url,"//user/jjoy/malleability/","");
 task_url = tranwrd(task_url,"/user/education/","");
 task_url = tranwrd(task_url,".xml&","");
 task_url = tranwrd(task_url,".jsp","");
 task_url = tranwrd(task_url,".xml","");
 task_url = tranwrd(task_url,"education/race/","");
 task_url = tranwrd(task_url,"/common/en-us/html/","");
RUN;

PROC SORT;
by session_id;
RUN;
PROC MEANS;
CLASS task_url;
VAR task_number;
RUN;
PROC transpose DATA = web_out.hometaskorder out = web_out.clean_hometask_order; 
BY session_id;
ID task_url; 
VAR task_number; 
RUN;

DATA web_out.clean_hometask_order; SET web_out.clean_hometask_order;
IF explicit = 44 THEN DO;
   IEorder = 1;
END;
ELSE IF  explicit = 46 THEN DO;
   IEorder = 2;
END;
RUN;

*IEorder = 1 MEANS explicit first;
*IEorder = 2 MEANS implicit first;


/********************************************************/
/*   Merging session with task (to get session_status)  */
/********************************************************/
DATA web_out.homesessions; SET web_in.homesessions;
KEEP 
session_id
session_status
user_id;
RUN;
PROC SORT;
BY session_id;
RUN;
PROC SORT DATA = web_out.clean_hometask_order;
BY session_id;
RUN;

DATA web_out.clean_hometask_order;
MERGE web_out.homesessions web_out.clean_hometask_order;
BY session_id;
RUN;


/********************************************************/
/*   Merging final session info (to get condition)      */
/********************************************************/
PROC SORT DATA = web_out.final_hometask_order;
BY session_id;
RUN;
DATA web_out.homesessioninfo_final; SET web_out.homesessioninfo;
KEEP
session_id
condition;
RUN;
DATA web_out.final_hometask_order;
MERGE web_out.clean_hometask_order web_out.homesessioninfo_final;
BY session_id;
RUN;

/********************************************************/
/*           DOING FINAL SORT OF ALL FILES              */
/********************************************************/
DATA race.raceiat;
MERGE 	race.race_iat_clean
		race.pairing(rename=(PB3=RPB3 PB4=RPB4 PB6=RPB6 PB7=RPB7))
		race.ns(rename=(NB3=RNB3 NB4=RNB4 NB6=RNB6 NB7=RNB7));by session_id;
raceiat = IAT;
REB3 = EB3;
REB4 = EB4;
REB6 = EB6;
REB7 = EB7;
R_exclude = subexcl;
KEEP raceiat session_id REB3 REB4 REB6 REB7 RNB3 RNB4 RNB6 RNB7 RPB3 RPB4 RPB6 RPB7 R_exclude;
PROC SORT;
BY session_id;
RUN;
DATA final_race_iat; SET race.raceiat;
RUN;

PROC SORT
DATA = final_race_iat;
BY session_id;
RUN;
PROC SORT DATA=web_out.clean_homeexplicit_all;
BY session_id;
RUN;
PROC SORT
DATA = web_out.final_hometask_order;
BY session_id;
RUN;


/********************************************************/
/*           MERGING ALL DATA TOGETHER                  */
/********************************************************/
DATA web_out.homefinal;
MERGE final_race_iat web_out.clean_homeexplicit_all web_out.final_hometask_order;
BY session_id;
RUN;
PROC contents DATA = web_out.homefinal;
RUN;


/********************************************************/
/*    CHECKING TO MAKE SURE MISSING DATA IS EXPECTED    */
/********************************************************/
PROC MEANS DATA=web_out.homefinal missing; *We have none in the DATA;
CLASS _ourip;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.homefinal missing;
CLASS study_name;
VAR session_id;
RUN;
PROC MEANS DATA=web_out.homefinal missing;
CLASS Condition;
VAR session_id;
RUN;


/********************************************************/
/*             DROPPING SS WHO DIDN'T GET A 0           */
/********************************************************/
DATA web_out.newhomefinal; SET web_out.homefinal;
IF R_exclude ne 0 THEN raceiat = .;
RUN;

/********************************************************/
/*         EXAMINING PEOPLE WHO GOT TO VERY END         */
/********************************************************/
DATA web_out.lefinhome; SET web_out.newhomefinal;
IF session_status ne 'C' THEN delete;
RUN;

PROC FREQ DATA = web_out.lefinhome;
TABLES condition;
RUN;

*condition 3 = 19;
*condition 4 = 18;
*condition 5 = 47;
*condition 6 = 50;

/********************************************************/
/*     EXAMINING WHO GOT >=30 MANIPULATIONS CORRECT      */
/********************************************************/
DATA web_out.mancheckhome; SET web_out.lefinhome;
where manip_correct >= 30;
newattrace1 = attrace1 - 4;
RUN;

PROC FREQ DATA = web_out.mancheckhome;
TABLES condition;
RUN;

*condition 3 = 18;
*condition 4 = 18;
*condition 5 = 47;
*condition 6 = 48;

*MERGING ALL DATA SETS;
PROC SORT DATA=web_out.mancheckhome;
by session_id;
RUN;
PROC SORT DATA=web_out.manchecklab;
by session_id;
RUN;
PROC SORT DATA=web_out.mancheckresearch;
by session_id;
RUN;
DATA web_out.completefinal;
merge web_out.mancheckhome web_out.manchecklab web_out.mancheckresearch;
by session_id;
RUN;

PROC FREQ DATA = web_out.completefinal;
TABLES condition;
RUN;


/********************************************************/
/*                   DEMOGRAPHICS                       */
/********************************************************/
PROC MEANS DATA = web_out.completefinal;
CLASS condition;
VAR Tblack1 Twhite1;
RUN;
*Getting general information about all VARiables;
PROC uniVARiate plot DATA = web_out.mancheckresearch;
VAR age raceomb1 religionid1 politicalid1 Tblack1 Twhite1;
RUN;

*Getting general information about IATs and number correct for manipulations;
PROC uniVARiate plot DATA = web_out.lefin;
CLASS condition;
VAR raceiat manip_correct;
RUN;

PROC MEANS DATA = web_out.completefinal;
CLASS condition;
VAR raceiat ;
RUN;



/********************************************************/
/*                   Looking at MEANS                   */
/********************************************************/
DATA web_out.completefinal; SET web_out.completefinal;
IF condition = 1 THEN location = 1;
IF condition = 2 THEN location = 1;
IF condition = 3 THEN location = 2;
IF condition = 4 THEN location = 2;
IF condition = 5 THEN location = 3;
IF condition = 6 THEN location = 3;

IF condition = 1 THEN cond = 1;
IF condition = 2 THEN cond = 2;
IF condition = 3 THEN cond = 1;
IF condition = 4 THEN cond = 2;
IF condition = 5 THEN cond = 1;
IF condition = 6 THEN cond = 2;

IF condition = 3 THEN sit = 1;
IF condition = 4 THEN sit = 1;
IF condition = 5 THEN sit = 2;
IF condition = 6 THEN sit = 2;

IF condition = 3 THEN ncond = 1;
IF condition = 4 THEN ncond = 2;
IF condition = 5 THEN ncond = 1;
IF condition = 6 THEN ncond = 2;

IF condition = 1 THEN test = 1;
IF condition = 2 THEN test = 2;

IF condition = 3 THEN ttest = 1;
IF condition = 4 THEN ttest = 2;

IF condition = 5 THEN tttest = 1;
IF condition = 6 THEN tttest = 2;
RUN;

PROC FREQ DATA = web_out.completefinal;
TABLES cond;
RUN;

PROC FREQ DATA = web_out.completefinal;
TABLES location;
RUN;

PROC MEANS DATA = web_out.completefinal;
CLASS cond location;
VAR raceiat;
RUN;

PROC MEANS DATA = web_out.completefinal;
CLASS newcond;
VAR raceiat;
WHERE IEorder = 2;
RUN;

PROC ttest DATA=web_out.completefinal;
CLASS test;
VAR raceiat;
RUN; 

PROC GLM DATA = web_out.completefinal;
CLASS cond location IEorder;
MODEL raceiat = cond|location/ ss3;
MEANS location/tukey alpha=0.05;
RUN;

PROC GLM DATA = web_out.completefinal;
CLASS ncond;
MODEL raceiat = ncond|sit/ ss3;
RUN;

*MEANS for the IAT;
ODS HTML;
PROC MEANS n mean std stderr DATA = web_out.completefinal;
CLASS condition;
VAR raceiat;
WHERE IEorder = 1;
RUN;
ODS HTML CLOSE;



